m_attribs.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /****************************************************************************
  2. * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. *
  3. * *
  4. * Permission is hereby granted, free of charge, to any person obtaining a *
  5. * copy of this software and associated documentation files (the *
  6. * "Software"), to deal in the Software without restriction, including *
  7. * without limitation the rights to use, copy, modify, merge, publish, *
  8. * distribute, distribute with modifications, sublicense, and/or sell *
  9. * copies of the Software, and to permit persons to whom the Software is *
  10. * furnished to do so, subject to the following conditions: *
  11. * *
  12. * The above copyright notice and this permission notice shall be included *
  13. * in all copies or substantial portions of the Software. *
  14. * *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  18. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  21. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  22. * *
  23. * Except as contained in this notice, the name(s) of the above copyright *
  24. * holders shall not be used in advertising or otherwise to promote the *
  25. * sale, use or other dealings in this Software without prior written *
  26. * authorization. *
  27. ****************************************************************************/
  28. /****************************************************************************
  29. * Author: Juergen Pfeifer, 1995,1997 *
  30. ****************************************************************************/
  31. /***************************************************************************
  32. * Module m_attribs *
  33. * Control menus display attributes *
  34. ***************************************************************************/
  35. #include "menu.priv.h"
  36. MODULE_ID("$Id: m_attribs.c,v 1.14 2004/12/11 23:29:12 tom Exp $")
  37. /* Macro to redraw menu if it is posted and changed */
  38. #define Refresh_Menu(menu) \
  39. if ( (menu) && ((menu)->status & _POSTED) )\
  40. {\
  41. _nc_Draw_Menu( menu );\
  42. _nc_Show_Menu( menu );\
  43. }
  44. /* "Template" macro to generate a function to set a menus attribute */
  45. #define GEN_MENU_ATTR_SET_FCT( name ) \
  46. NCURSES_IMPEXP int NCURSES_API set_menu_ ## name (MENU * menu, chtype attr)\
  47. {\
  48. T((T_CALLED("set_menu_" #name "(%p,%s)"), menu, _traceattr(attr)));\
  49. if (!(attr==A_NORMAL || (attr & A_ATTRIBUTES)==attr))\
  50. RETURN(E_BAD_ARGUMENT);\
  51. if (menu && ( menu -> name != attr))\
  52. {\
  53. (menu -> name) = attr;\
  54. Refresh_Menu(menu);\
  55. }\
  56. Normalize_Menu( menu ) -> name = attr;\
  57. RETURN(E_OK);\
  58. }
  59. /* "Template" macro to generate a function to get a menu's attribute */
  60. #define GEN_MENU_ATTR_GET_FCT( name ) \
  61. NCURSES_IMPEXP chtype NCURSES_API menu_ ## name (const MENU * menu)\
  62. {\
  63. T((T_CALLED("menu_" #name "(%p)"), menu));\
  64. returnAttr(Normalize_Menu( menu ) -> name);\
  65. }
  66. /*---------------------------------------------------------------------------
  67. | Facility : libnmenu
  68. | Function : int set_menu_fore(MENU *menu, chtype attr)
  69. |
  70. | Description : Set the attribute for selectable items. In single-
  71. | valued menus this is used to highlight the current
  72. | item ((i.e. where the cursor is), in multi-valued
  73. | menus this is used to highlight the selected items.
  74. |
  75. | Return Values : E_OK - success
  76. | E_BAD_ARGUMENT - an invalid value has been passed
  77. +--------------------------------------------------------------------------*/
  78. GEN_MENU_ATTR_SET_FCT(fore)
  79. /*---------------------------------------------------------------------------
  80. | Facility : libnmenu
  81. | Function : chtype menu_fore(const MENU* menu)
  82. |
  83. | Description : Return the attribute used for selectable items that
  84. | are current (single-valued menu) or selected (multi-
  85. | valued menu).
  86. |
  87. | Return Values : Attribute value
  88. +--------------------------------------------------------------------------*/
  89. GEN_MENU_ATTR_GET_FCT(fore)
  90. /*---------------------------------------------------------------------------
  91. | Facility : libnmenu
  92. | Function : int set_menu_back(MENU *menu, chtype attr)
  93. |
  94. | Description : Set the attribute for selectable but not yet selected
  95. | items.
  96. |
  97. | Return Values : E_OK - success
  98. | E_BAD_ARGUMENT - an invalid value has been passed
  99. +--------------------------------------------------------------------------*/
  100. GEN_MENU_ATTR_SET_FCT(back)
  101. /*---------------------------------------------------------------------------
  102. | Facility : libnmenu
  103. | Function : chtype menu_back(const MENU *menu)
  104. |
  105. | Description : Return the attribute used for selectable but not yet
  106. | selected items.
  107. |
  108. | Return Values : Attribute value
  109. +--------------------------------------------------------------------------*/
  110. GEN_MENU_ATTR_GET_FCT(back)
  111. /*---------------------------------------------------------------------------
  112. | Facility : libnmenu
  113. | Function : int set_menu_grey(MENU *menu, chtype attr)
  114. |
  115. | Description : Set the attribute for unselectable items.
  116. |
  117. | Return Values : E_OK - success
  118. | E_BAD_ARGUMENT - an invalid value has been passed
  119. +--------------------------------------------------------------------------*/
  120. GEN_MENU_ATTR_SET_FCT(grey)
  121. /*---------------------------------------------------------------------------
  122. | Facility : libnmenu
  123. | Function : chtype menu_grey(const MENU *menu)
  124. |
  125. | Description : Return the attribute used for non-selectable items
  126. |
  127. | Return Values : Attribute value
  128. +--------------------------------------------------------------------------*/
  129. GEN_MENU_ATTR_GET_FCT(grey)
  130. /* m_attribs.c ends here */