home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / WNDSPLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  7.3 KB  |  238 lines

  1. /**
  2. *
  3. * Name        wndsplay -- Display window on video page with border.
  4. *
  5. * Synopsis    presult = wndsplay(pwin,pwhere,pbord);
  6. *
  7. *        BWINDOW *presult  Pointer to newly-displayed BWINDOW
  8. *                  structure, or NIL if failure.
  9. *        BWINDOW *pwin      Pointer to BWINDOW structure to
  10. *                  display.
  11. *        WHERE    *pwhere   Pointer to WHERE structure denoting
  12. *                  device, display page, and coordinates
  13. *                  where window is to be displayed.
  14. *        BORDER    *pbord      Pointer to BORDER structure denoting
  15. *                  type of border to put around window.
  16. *
  17. * Description    This function displays a window on a given video device
  18. *        and display page and adds a border.
  19. *
  20. *        The window is made current (selected for I/O).
  21. *
  22. *        The window's cursor is activated (although the cursor
  23. *        may be invisible).  The cursors of other windows on that
  24. *        page are deactivated.
  25. *
  26. *        An error occurs if pwin does not point to a valid window
  27. *        structure.  An error also occurs if the location where
  28. *        the window is to be displayed is impossible, for example
  29. *        if an unknown device is requested or if the dimensions
  30. *        of the window exceed the screen's dimensions.
  31. *
  32. * Returns    presult       Pointer to newly-displayed BWINDOW
  33. *                  structure, or NIL if failure.
  34. *        b_pcurwin      Pointer to newly-displayed BWINDOW
  35. *                  structure, or unchanged if failure.
  36. *        *pwin          Several fields altered.
  37. *        b_wnlist[][]      Linked list altered.
  38. *        b_pactnode[][]      Window node with active cursor.
  39. *        b_wnerr       Possible values:
  40. *                  (No change)       Success.
  41. *                  WN_BAD_WIN       *pwin is invalid.
  42. *                  WN_ALREADY_SHOWN Already shown.
  43. *                  WN_BAD_DEV       Unknown device or
  44. *                            window dimensions
  45. *                            overflow screen.
  46. *                  WN_NO_MEMORY      Insufficient memory.
  47. *                  WN_BAD_NODE      Internal error.
  48. *                  WN_BAD_PAGE      Internal error.
  49. *                  WN_COVERED      Internal error.
  50. *                  WN_ILL_DIM      Internal error.
  51. *                  WN_NOT_SHOWN      Internal error.
  52. *                  WN_NULL_PTR      Internal error.
  53. *
  54. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  55. *
  56. * Version    3.02 March 23, 1987
  57. *        Corrected handling of pwin->prev.pdata when redisplaying
  58. *            window.
  59. *        Preserved WNUNHIDE error codes from being obscured by
  60. *            subsequent errors.
  61. *
  62. **/
  63.  
  64. #include <bwindow.h>
  65.  
  66. #if MSC300
  67. #include <malloc.h>
  68. #include <memory.h>
  69. #else
  70. #include <stdlib.h>
  71. #endif
  72.  
  73.                       /* Internal function (see below)*/
  74. static REGION *bordim(REGION *,DIM *,BORDER *,WHERE *);
  75.  
  76. BWINDOW *wndsplay(pwin,pwhere,pborder)
  77. BWINDOW *pwin;
  78. WHERE    *pwhere;
  79. BORDER    *pborder;
  80. {
  81.     REGION occupied;              /* Region occupied by window    */
  82.                       /* and border.              */
  83.     int old_npage;
  84.  
  85.     if (wnvalwin(pwin) == NIL)          /* Validate window structure.   */
  86.     {
  87.     wnerror(WN_BAD_WIN);
  88.     return NIL;
  89.     }
  90.  
  91.     if (   pwin->where_shown.dev == MONO    /* Confirm that window is */
  92.     || pwin->where_shown.dev == COLOR)  /* not currently shown.   */
  93.     {
  94.     wnerror(WN_ALREADY_SHOWN);
  95.     return NIL;
  96.     }
  97.  
  98.     if (wnseldev(pwhere,&pwin->img.dim,&old_npage))
  99.                       /* Validate device, page, and   */
  100.     {                      /* dimensions and select device */
  101.     wnerror(WN_BAD_DEV);          /* and page.              */
  102.     return NIL;
  103.     }
  104.  
  105.                       /* Obtain overall dimensions    */
  106.                       /* including the border.          */
  107.     bordim(&occupied,&pwin->img.dim,pborder,pwhere);
  108.     utcopy(&pwin->where_prev,pwhere,WHERE);
  109.     utcopy(&pwin->where_prev.corner,&occupied.ul,LOC);
  110.  
  111.     if (pwin->options.removable)
  112.     {                      /* Removable window:          */
  113.     if (pwin->prev.pdata != NIL)
  114.     {                  /* Already have a buffer for    */
  115.                       /* previous screen contents.    */
  116.         if (  REGION_H(occupied) * REGION_H(occupied)
  117.         > pwin->prev.dim.h   * pwin->prev.dim.w  )
  118.         {                  /* Existing buffer too small,   */
  119.         free((char *) pwin->prev.pdata);    /* so discard it. */
  120.         pwin->prev.pdata = NIL;
  121.         }
  122.     }
  123.     pwin->prev.dim.h = REGION_H(occupied);
  124.     pwin->prev.dim.w = REGION_W(occupied);
  125.     if (pwin->prev.pdata == NIL)
  126.     {                  /* Allocate space for previous  */
  127.                       /* screen contents.          */
  128.         if (wnmkimg(&pwin->prev) == NIL)
  129.         return NIL;
  130.     }
  131.     }
  132.     pwin->prev.dim.h = REGION_H(occupied);
  133.     pwin->prev.dim.w = REGION_W(occupied);
  134.  
  135.     utcopy(&pwin->where_shown,pwhere, WHERE); /* Record where shown   */
  136.     utcopy(&pwin->bord,       pborder,BORDER);     /* and border.       */
  137.  
  138.     /* Display the window by                          */
  139.     /*      1) adding this window to linked list for this display page; */
  140.     /*      2) marking it hidden;                       */
  141.     /*      3) un-hiding it.                          */
  142.  
  143.     if ((pwin->pnode = wnpgadd(pwin,pwhere->dev,pwhere->page)) == NIL)
  144.     {
  145.        pwin->where_shown.dev = ABSENT;
  146.        return NIL;
  147.     }
  148.  
  149.     pwin->options.hidden = 1;
  150.  
  151.     if (wnunhide(pwin) == NIL)
  152.     {
  153.     if (pwin->where_shown.dev != ABSENT)
  154.     {                  /* Clean up after error.          */
  155.         wnpgrem(pwin);
  156.         pwin->where_shown.dev = ABSENT;
  157.     }
  158.     }
  159.  
  160.     wnselect(pwin);              /* Select for I/O           */
  161.     wncursor(pwin);              /* Select this window as the    */
  162.                       /* one on this page to have an  */
  163.                       /* active cursor.           */
  164.  
  165.     return pwin;              /* Success.              */
  166. }
  167.  
  168. /**
  169. *
  170. * Name        bordim -- Calculate actual dimensions required by a
  171. *              border around a rectangular region
  172. *              on the current display device.
  173. *
  174. * Synopsis    presult = bordim(pregion,pdim,pborder,pwhere);
  175. *
  176. *        REGION    *presult  Pointer to structure describing
  177. *                  location and dimensions of the region
  178. *                  to be occupied by the border.
  179. *        REGION    *pregion  Pointer to structure describing
  180. *                  location and dimensions of the region
  181. *                  to be occupied by the border.
  182. *        DIM    *pdim      Pointer to structure describing
  183. *                  dimensions of rectangular region to
  184. *                  be surrounded by border.
  185. *        BORDER    *pborder  Pointer to structure describing
  186. *                  type of border.
  187. *        WHERE    *pwhere   Pointer to WHERE structure denoting
  188. *                  location of rectangular region to be
  189. *                  surrounded by border.
  190. *
  191. * Description    This function calculates the actual dimensions required
  192. *        by a border around a rectangular region on the current
  193. *        display device.  It takes into account the way WNPUTBOR
  194. *        works at the edges of the screen.
  195. *
  196. *        This function assumes that the rectangular region fits
  197. *        on the current screen.
  198. *
  199. * Returns    *presult,*pregion Pointer to structure describing
  200. *                  location and dimensions of the region
  201. *                  to be occupied by the border.
  202. *
  203. **/
  204.  
  205. static REGION *bordim(pregion,pdim,pborder,pwhere)
  206. REGION          *pregion;
  207. DIM          *pdim;
  208. BORDER          *pborder;
  209. WHERE          *pwhere;
  210. {
  211.     int    bottom_row,right_column;
  212.     int    mode,columns,act_page;
  213.  
  214.     bottom_row     = pwhere->corner.row + pdim->h;
  215.     right_column = pwhere->corner.col + pdim->w;
  216.  
  217.     if (pborder->type          == 0
  218.     || pwhere->corner.row <= 0
  219.     || pwhere->corner.col <= 0
  220.     || bottom_row          >= scrows()
  221.     || (scmode(&mode,&columns,&act_page),
  222.         (right_column     >= columns)))
  223.     {
  224.     utcopy(&pregion->ul,&pwhere->corner,LOC);
  225.     pregion->lr.row = bottom_row   - 1;
  226.     pregion->lr.col = right_column - 1;
  227.     }
  228.     else
  229.     {
  230.     pregion->ul.row = pwhere->corner.row - 1;
  231.     pregion->ul.col = pwhere->corner.col - 1;
  232.     pregion->lr.row = bottom_row;
  233.     pregion->lr.col = right_column;
  234.     }
  235.  
  236.     return pregion;
  237. }
  238.