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

  1. /**
  2. *
  3. * Name        MNCREAT0 -- Allocate and create a menu structure.
  4. *
  5. * Synopsis    pmenu = mncreat0 (height, width,
  6. *                  textattr, hilattr, proattr, longattr,
  7. *                  signature);
  8. *
  9. *        BMENU *pmenu    Pointer to newly-created BMENU
  10. *                structure, or NIL if failure.
  11. *        int height    Number of rows      in data area.
  12. *        int width    Number of columns in data area.
  13. *        int textattr    Default attribute in data area.
  14. *        int hilattr    Attribute of highlight bar.
  15. *        int proattr    Attribute of "protected" items.
  16. *        int longattr    Attribute of long descriptions (if any).
  17. *        unsigned signature
  18. *                Signature word expected by calling
  19. *                function.
  20. *
  21. * Description    This function allocates space for a menu structure and
  22. *        fills it with default values.  This includes a call
  23. *        to WNCREATE.
  24. *
  25. *        An error occurs if the menu dimensions exceed maximum
  26. *        screen dimensions or if the memory allocation fails.
  27. *
  28. *        This function is invoked by the mncreate() macro, which
  29. *        provides the signature value.  The same signature value
  30. *        is provided to MNVALMN0 by the mnvalmnu() macro.  By
  31. *        using these macros, all menu functions provide signature
  32. *        values for comparison.    In this way incompatible
  33. *        versions of BMENU.H can be detected at run time.
  34. *
  35. *        Use MNDSTROY to discard the BMENU structure and
  36. *        related internal data structures.
  37. *
  38. * Returns    presult       Pointer to newly-created BMENU
  39. *                  structure, or NIL if failure.
  40. *        b_wnerr       Possible values:
  41. *                  (No change)      Success.
  42. *                  WN_ILL_DIM      Invalid dimensions.
  43. *                  WN_NO_MEMORY      Insufficient memory.
  44. *
  45. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  46. *
  47. **/
  48.  
  49. #include <bmenu.h>
  50.  
  51. BMENU *mncreat0 (height, width, textattr, hilattr, proattr, longattr,
  52.          signature)
  53. int    height, width, textattr, hilattr, proattr, longattr;
  54. unsigned signature;
  55. {
  56.     BMENU *pmenu;
  57.     int    err;
  58.  
  59.         /* Attempt to allocate space for BMENU structure.   */
  60.     if ((pmenu = utalloc (BMENU)) == NIL)
  61.     wnreterr (WN_NO_MEMORY);
  62.  
  63.         /* Set pointers to NIL, stuff in given values.        */
  64.     pmenu->pitems   = NIL;
  65.     pmenu->pkeys    = NIL;
  66.     pmenu->hilattr  = hilattr;
  67.     pmenu->proattr  = proattr;
  68.     pmenu->longattr = longattr;
  69.  
  70.         /* Create this menu's window.                       */
  71.     if ((pmenu->pwin = wncreate (height, width, textattr)) == NIL)
  72.     {
  73.     free (pmenu);
  74.     return (NIL);
  75.     }
  76.  
  77.         /* Create signature.                    */
  78.     pmenu->signature = signature;
  79.  
  80.         /* Create default key bindings list for this menu.  */
  81.     if (mndefkey (pmenu) == NIL)
  82.     {
  83.     err = b_wnerr;
  84.     mndlkeys (pmenu);
  85.     wndstroy (pmenu->pwin);
  86.     pmenu->signature = BMENU_DEAD;
  87.     free (pmenu);
  88.     wnreterr (err);
  89.     }
  90.  
  91.     pmenu->pwin->options.cur_track = 0; /* Disable cursor tracking. */
  92.  
  93.         /* Turn the window cursor off (so our highlight bar */
  94.         /* looks good).                     */
  95.     wnsetopt (pmenu->pwin, WN_CUR_OFF, 1);
  96.  
  97.     return (pmenu);
  98. }
  99.