home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / HLREAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  8.9 KB  |  296 lines

  1. /**
  2. *
  3. * Name        HLREAD -- Display help in a virtual window and read
  4. *              user responses.
  5. *
  6. * Synopsis    presult = hlread (pwin, phelp_win, ptext, text_length,
  7. *                  pfinal, option);
  8. *
  9. *        WN_EVENT *presult    pfinal, or NIL if an error
  10. *                    occured.
  11. *        BWINDOW *pwin        Pointer to window in which to
  12. *                    display help text, or NIL if
  13. *                    HLREAD is to create one.
  14. *        HL_WINDOW *phelp_win    Pointer to the help window
  15. *                    descriptor to use in construct-
  16. *                    ing and building the help
  17. *                    window, or NIL to use default.
  18. *        const char *ptext    Pointer to help text to be
  19. *                    displayed.
  20. *        int text_length     Length of the text to be
  21. *                    displayed.
  22. *        WN_EVENT *pfinal    Pointer to structure to fill in
  23. *                    with a copy of the event which
  24. *                    terminated the read.
  25. *        int option        Bitwise ORing of the following:
  26. *                    HL_REMOVE_WIN:    Remove the
  27. *                      window before returning.
  28. *                    HL_DESTROY_WIN: Remove and
  29. *                      destroy the window before
  30. *                      returning.
  31. *                    ORed with one of the following:
  32. *                    HL_CHARS_ONLY:
  33. *                      *ptext contains characters
  34. *                      only.
  35. *                    HL_CHAR_ATTR:
  36. *                      *ptext contains character/
  37. *                      attribute pairs.
  38. *                    HL_COMPRESSED:
  39. *                      *ptext points to text which
  40. *                      is in UTSQZSCN format.
  41. *                    ORed with one of the following:
  42. *                    HL_USE_MOUSE: Use the mouse if
  43. *                      it is present.
  44. *                    HL_NO_MOUSE: Do not use the
  45. *                      mouse.
  46. *                    HL_KBIGNORE: Ignore the keyboard
  47. *                      and discard all keystrokes.
  48. *
  49. *
  50. * Description    This function accepts a pointer to help text and
  51. *        parameters describing the window it should be displayed
  52. *        in, constructs and displays the window, and reads user
  53. *        responses from it until a terminating event is
  54. *        encountered.
  55. *
  56. *        The help window's characteristics (i.e., viewport size,
  57. *        attributes, etc.) are taken from the help window
  58. *        descriptor pointed to by *phelp_win.
  59. *
  60. *        If pwin is NIL, then the window will be created and
  61. *        displayed by HLREAD; upon exit, it will always be
  62. *        removed and destroyed.    If pwin is non-NIL, then the
  63. *        help text is displayed in it rather than creating a
  64. *        new one; HLREAD will remove and/or destroy it according
  65. *        to the value of option.
  66. *
  67. *        An error occurs if the location where the window is to
  68. *        be displayed is impossible, for example if  the
  69. *        dimensions of the viewport exceed the screen's or the
  70. *        data area's dimensions.
  71. *
  72. *        The return value is a pointer to the event node which
  73. *        terminated the read.  Note that if pwin is NIL, or
  74. *        the HL_DESTROY_WIN option is specified, the pointer
  75. *        will point to an internal static copy of the event
  76. *        structure; this copy will be overwritten with each call
  77. *        to HLREAD.
  78. *
  79. * Returns    *pfinal       Copy of event node which terminated
  80. *                  the read process (the event's action
  81. *                  will be either WN_TRANSMIT or
  82. *                  WN_ABORT).
  83. *        b_pcurwin      If HL_REMOVE_WIN or HL_DESTROY_WIN
  84. *                  is not specified, pointer to
  85. *                  newly-displayed BWINDOW structure,
  86. *                  or unchanged if failure.
  87. *        b_wnerr       Possible values:
  88. *                  (No change)       Success.
  89. *                  HL_NO_EXIT       No event will
  90. *                            transmit or abort
  91. *                            the window.
  92. *                  HL_BAD_OPT       Unknown option
  93. *                            specified.
  94. *                  WN_BAD_DEV       Unknown device or
  95. *                            window dimensions
  96. *                            overflow screen.
  97. *                  WN_ILL_DIM       Viewport is larger
  98. *                            than data area, or
  99. *                            origin is illegal.
  100. *                  WN_NO_MEMORY       Insufficient memory.
  101. *                  WN_BAD_WIN       Internal error.
  102. *                  WN_ALREADY_SHOWN Internal error.
  103. *                  WN_BAD_NODE       Internal error.
  104. *                  WN_BAD_PAGE       Internal error.
  105. *                  WN_COVERED       Internal error.
  106. *                  WN_NOT_SHOWN       Internal error.
  107. *                  WN_NULL_PTR       Internal error.
  108. *
  109. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  110. *
  111. **/
  112.  
  113. #include <bhelp.h>
  114. #include <bwindow.h>
  115. #include <butil.h>
  116.  
  117.  
  118. HL_WINDOW b_def_help_win =        /* Default help record window.  */
  119. {                    /*                    */
  120.      5,  9,                /* Viewport top left corner.    */
  121.     19, 69,                /* Viewport bottom right corner.*/
  122.      0,  0,                /* Data area origin coordinates.*/
  123.     NORMAL | INTENSITY, SC_CYAN,    /* Window foreground/background.*/
  124.     0,                    /* Default border (BBRD_SSSS).  */
  125.     NORMAL | INTENSITY, SC_CYAN,    /* Border foreground/background.*/
  126.     BBRD_NO_TITLE,            /* Title position.            */
  127.     NORMAL | INTENSITY, SC_BLUE,    /* Title foreground/background. */
  128.     15,                 /* Number of rows in data area. */
  129.     61,                 /* # of columns in data area.   */
  130.     SC_BLUE, SC_CYAN,            /* Cross reference attributes.  */
  131.     SC_BLUE | INTENSITY, NORMAL,    /* Highlighted cross reference. */
  132.     {'\0'}                          /* # of columns in data area.   */
  133. };
  134.  
  135. const static int title_table[] =    /* Table of title positions.    */
  136. {
  137.     BBRD_TCT,
  138.     BBRD_TRT,
  139.     BBRD_TLT,
  140.     BBRD_BCT,
  141.     BBRD_BRT,
  142.     BBRD_BLT
  143. };
  144.  
  145.  
  146. WN_EVENT *hlread(pwin, phelp_win, ptext, text_length, pfinal,
  147.            option)
  148. BWINDOW      *pwin;
  149. const HL_WINDOW  *phelp_win;
  150. const char     *ptext;
  151. int          text_length;
  152. WN_EVENT     *pfinal;
  153. int          option;
  154. {
  155.     int          save_error;
  156.     int          made_window = 0;
  157.     char        *pwindow_data;
  158.     int          dest_length;
  159.     int          mode, columns;
  160.     BORDER         border;
  161.     WHERE         where;
  162.     const HL_WINDOW *phelp_window;
  163.  
  164.     if (phelp_win == NIL)
  165.     phelp_window = &b_def_help_win;
  166.     else
  167.     phelp_window = phelp_win;
  168.  
  169.     if (pwin == NIL)
  170.     {
  171.     pwin = wncreate(phelp_window->data_rows,
  172.             phelp_window->data_columns,
  173.             utnybbyt(phelp_window->data_back,
  174.                  phelp_window->data_fore));
  175.     if (pwin == NIL)
  176.         return(NIL);
  177.  
  178.     if (wnsetopt(pwin, WN_CUR_OFF, 1) == NIL)
  179.     {
  180.         save_error = b_wnerr;
  181.         wndstroy(pwin);
  182.         hlreterr(save_error);
  183.     }
  184.  
  185.     made_window = 1;
  186.     }
  187.  
  188.         /* If the window is not displayed, set up a WHERE   */
  189.         /* and a BORDER for it based on the default help    */
  190.         /* window.  Otherwise, just make a copy of the        */
  191.         /* values stored in the window.             */
  192.     if ((pwin->where_shown.dev != SC_COLOR) &&
  193.     (pwin->where_shown.dev != SC_MONO))
  194.     {
  195.     where.dev     = scmode(&mode, &columns, &where.page);
  196.     where.corner.row = phelp_window->view_top;
  197.     where.corner.col = phelp_window->view_left;
  198.  
  199.     if (!utrange(phelp_window->border_type, 0, 15))
  200.         border.type = phelp_window->border_type + 1;
  201.     else
  202.         if (phelp_window->border_type == 255)
  203.         border.type = BBRD_NO_BORDER;
  204.         else
  205.         {
  206.         border.type = 31;
  207.         border.ch = phelp_window->border_type;
  208.         }
  209.     border.attr = utnybbyt(phelp_window->border_back,
  210.                    phelp_window->border_fore);
  211.  
  212.     if (utrange(phelp_window->title_type, 0,
  213.         (sizeof(title_table) / sizeof(title_table[0])) - 1) ||
  214.         (phelp_window->pwindow_title == NIL)        ||
  215.         (phelp_window->pwindow_title[0] == '\0'))
  216.     {
  217.         border.type |= BBRD_NO_TITLE;
  218.     }
  219.     else
  220.         border.type |= title_table[phelp_window->title_type];
  221.  
  222.     if (border.type != BBRD_NO_BORDER)
  223.         if (border.type & (BBRD_TLT | BBRD_TCT | BBRD_TRT))
  224.         {
  225.         border.pttitle = phelp_window->pwindow_title;
  226.         border.ttattr = utnybbyt(phelp_window->title_back,
  227.                      phelp_window->title_fore);
  228.         }
  229.         else
  230.         if (border.type & (BBRD_BLT | BBRD_BCT | BBRD_BRT))
  231.         {
  232.             border.pbtitle = phelp_window->pwindow_title;
  233.             border.btattr = utnybbyt(phelp_window->title_back,
  234.                          phelp_window->title_fore);
  235.         }
  236.     }
  237.     else
  238.     {
  239.     memcpy(&where, &(pwin->where_shown), sizeof(where));
  240.     memcpy(&border, &(pwin->bord), sizeof(border));
  241.     }
  242.  
  243.     if (wnselect(pwin) == NIL)
  244.     {
  245.     save_error = b_wnerr;
  246.     if (made_window)
  247.         wndstroy(pwin);
  248.     hlreterr(save_error);
  249.     }
  250.  
  251.     switch (option & HL_TEXT_TYPE)
  252.     {
  253.     case HL_CHARS_ONLY:
  254.     wnwrrect(pwin, 0, 0, wndata_h(pwin) - 1, wndata_w(pwin) - 1,
  255.          ptext, -1, -1, CHARS_ONLY);
  256.     break;
  257.  
  258.     case HL_CHAR_ATTR:
  259.     wnwrrect(pwin, 0, 0, wndata_h(pwin) - 1, wndata_w(pwin) - 1,
  260.          ptext, -1, -1, CHAR_ATTR);
  261.     break;
  262.  
  263.     case HL_COMPRESSED:
  264.     pwindow_data = (char *) pwin->img.pdata;
  265.     dest_length  =    phelp_window->data_columns *
  266.             phelp_window->data_rows * 2;
  267.     utunsqz(ptext, pwindow_data, text_length, dest_length);
  268.     break;
  269.  
  270.     default:
  271.     hlreterr(HL_BAD_OPT);
  272.     }
  273.  
  274.         /* Now read user responses from the window.  Note   */
  275.         /* that if the window is already displayed, the     */
  276.         /* viewport dimensions, starting origin, where and  */
  277.         /* border structures are all ignored.            */
  278.     wnread(pwin, &where,
  279.        phelp_window->view_bottom - phelp_window->view_top + 1,
  280.        phelp_window->view_right - phelp_window->view_left + 1,
  281.        phelp_window->origin_row, phelp_window->origin_col,
  282.        &border, pfinal, (option & (HL_NO_MOUSE | HL_KBIGNORE)));
  283.  
  284.     if (made_window || (option & HL_REMOVE_WIN))
  285.     if (wnremove(pwin) == NIL)
  286.         return(NIL);
  287.  
  288.     if (made_window || (option & HL_DESTROY_WIN))
  289.     {
  290.     if (wndstroy(pwin) != WN_NO_ERROR)
  291.         return(NIL);
  292.     }
  293.  
  294.     return(pfinal);
  295. }
  296.