home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ncurses-1.9.9e-src.tgz / tar.out / fsf / ncurses / menu / m_attribs.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  7KB  |  170 lines

  1.  
  2. /***************************************************************************
  3. *                            COPYRIGHT NOTICE                              *
  4. ****************************************************************************
  5. *                ncurses is copyright (C) 1992-1995                        *
  6. *                          Zeyd M. Ben-Halim                               *
  7. *                          zmbenhal@netcom.com                             *
  8. *                          Eric S. Raymond                                 *
  9. *                          esr@snark.thyrsus.com                           *
  10. *                                                                          *
  11. *        Permission is hereby granted to reproduce and distribute ncurses  *
  12. *        by any means and for any fee, whether alone or as part of a       *
  13. *        larger distribution, in source or in binary form, PROVIDED        *
  14. *        this notice is included with any such distribution, and is not    *
  15. *        removed from any of its header files. Mention of ncurses in any   *
  16. *        applications linked with it is highly appreciated.                *
  17. *                                                                          *
  18. *        ncurses comes AS IS with no warranty, implied or expressed.       *
  19. *                                                                          *
  20. ***************************************************************************/
  21.  
  22. /***************************************************************************
  23. * Module menu_attribs                                                      *
  24. * Control menus display attributes                                         *
  25. ***************************************************************************/
  26.  
  27. #include "menu.priv.h"
  28.  
  29. /* Macro to redraw menu if it is posted and changed */
  30. #define Refresh_Menu(menu) \
  31.    if ( (menu) && ((menu)->status & _POSTED) )\
  32.    {\
  33.       _nc_Draw_Menu( menu );\
  34.       _nc_Show_Menu( menu );\
  35.    }
  36.  
  37. /* "Template" macro to generate a function to set a menus attribute */
  38. #define GEN_MENU_ATTR_SET_FCT( name ) \
  39. int set_menu_ ## name (MENU * menu, chtype attr)\
  40. {\
  41.    if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\
  42.       RETURN(E_BAD_ARGUMENT);\
  43.    if (menu && ( menu -> name != attr))\
  44.      {\
  45.        (menu -> name) = attr;\
  46.        Refresh_Menu(menu);\
  47.      }\
  48.    Normalize_Menu( menu ) -> name = attr;\
  49.    RETURN(E_OK);\
  50. }
  51.  
  52. /* "Template" macro to generate a function to get a menus attribute */
  53. #define GEN_MENU_ATTR_GET_FCT( name ) \
  54. chtype menu_ ## name (const MENU * menu)\
  55. {\
  56.    return (Normalize_Menu( menu ) -> name);\
  57. }
  58.  
  59. /*---------------------------------------------------------------------------
  60. |   Facility      :  libnmenu  
  61. |   Function      :  int set_menu_fore(MENU *menu, chtype attr)
  62. |   
  63. |   Description   :  Set the attribute for selectable items. In single-
  64. |                    valued menus thiis is used to highlight the current
  65. |                    item ((i.e. where the cursor is), in multi-valued
  66. |                    menus this is used to highlight the selected items.
  67. |
  68. |   Return Values :  E_OK              - success
  69. |                    E_BAD_ARGUMENT    - an invalid value has been passed   
  70. +--------------------------------------------------------------------------*/
  71. GEN_MENU_ATTR_SET_FCT( fore )
  72.  
  73. /*---------------------------------------------------------------------------
  74. |   Facility      :  libnmenu  
  75. |   Function      :  chtype menu_fore(const MENU* menu)
  76. |   
  77. |   Description   :  Return the attribute used for selectable items that
  78. |                    are current (single-valued menu) or selected (multi-
  79. |                    valued menu).   
  80. |
  81. |   Return Values :  Attribute value
  82. +--------------------------------------------------------------------------*/
  83. GEN_MENU_ATTR_GET_FCT( fore )
  84.  
  85. /*---------------------------------------------------------------------------
  86. |   Facility      :  libnmenu  
  87. |   Function      :  int set_menu_back(MENU *menu, chtype attr)
  88. |   
  89. |   Description   :  Set the attribute for selectable but not yet selected
  90. |                    items.
  91. |
  92. |   Return Values :  E_OK             - success  
  93. |                    E_BAD_ARGUMENT   - an invalid value has been passed
  94. +--------------------------------------------------------------------------*/
  95. GEN_MENU_ATTR_SET_FCT( back )
  96.  
  97. /*---------------------------------------------------------------------------
  98. |   Facility      :  libnmenu  
  99. |   Function      :  chtype menu_back(const MENU *menu)
  100. |   
  101. |   Description   :  Return the attribute used for selectable but not yet
  102. |                    selected items. 
  103. |
  104. |   Return Values :  Attribute value
  105. +--------------------------------------------------------------------------*/
  106. GEN_MENU_ATTR_GET_FCT( back )
  107.  
  108. /*---------------------------------------------------------------------------
  109. |   Facility      :  libnmenu  
  110. |   Function      :  int set_menu_grey(MENU *menu, chtype attr)
  111. |   
  112. |   Description   :  Set the attribute for unselectable items.
  113. |
  114. |   Return Values :  E_OK             - success
  115. |                    E_BAD_ARGUMENT   - an invalid value has been passed    
  116. +--------------------------------------------------------------------------*/
  117. GEN_MENU_ATTR_SET_FCT( grey )
  118.  
  119. /*---------------------------------------------------------------------------
  120. |   Facility      :  libnmenu  
  121. |   Function      :  chtype menu_grey(const MENU *menu)
  122. |   
  123. |   Description   :  Return the attribute used for non-selectable items
  124. |
  125. |   Return Values :  Attribute value
  126. +--------------------------------------------------------------------------*/
  127. GEN_MENU_ATTR_GET_FCT( grey )
  128.  
  129. /*---------------------------------------------------------------------------
  130. |   Facility      :  libnmenu  
  131. |   Function      :  int set_menu_pad(MENU *menu, int pad)
  132. |   
  133. |   Description   :  Set the character to be used to separate the item name
  134. |                    from its description. This must be a printable 
  135. |                    character.
  136. |
  137. |   Return Values :  E_OK              - success
  138. |                    E_BAD_ARGUMENT    - an invalid value has been passed
  139. +--------------------------------------------------------------------------*/
  140. int set_menu_pad(MENU *menu, int pad)
  141. {
  142.   bool do_refresh = !(menu);
  143.  
  144.   if (!isprint((unsigned char)pad))
  145.     RETURN(E_BAD_ARGUMENT);
  146.   
  147.   Normalize_Menu( menu );
  148.   menu->pad = pad;
  149.   
  150.   if (do_refresh)
  151.       Refresh_Menu( menu );
  152.  
  153.   RETURN(E_OK);
  154. }
  155.  
  156. /*---------------------------------------------------------------------------
  157. |   Facility      :  libnmenu  
  158. |   Function      :  int menu_pad(const MENU *menu)
  159. |   
  160. |   Description   :  Return the value of the padding character
  161. |
  162. |   Return Values :  The pad character
  163. +--------------------------------------------------------------------------*/
  164. int menu_pad(const MENU * menu)
  165. {
  166.   return (Normalize_Menu( menu ) -> pad);
  167. }
  168.  
  169. /* m_attribs.c ends here */
  170.