m_item_opt.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_item_opt *
  33. * Menus item option routines *
  34. ***************************************************************************/
  35. #include "menu.priv.h"
  36. MODULE_ID("$Id: m_item_opt.c,v 1.17 2004/12/25 21:32:54 tom Exp $")
  37. /*---------------------------------------------------------------------------
  38. | Facility : libnmenu
  39. | Function : int set_item_opts(ITEM *item, Item_Options opts)
  40. |
  41. | Description : Set the options of the item. If there are relevant
  42. | changes, the item is connected and the menu is posted,
  43. | the menu will be redisplayed.
  44. |
  45. | Return Values : E_OK - success
  46. | E_BAD_ARGUMENT - invalid item options
  47. +--------------------------------------------------------------------------*/
  48. NCURSES_EXPORT(int)
  49. set_item_opts(ITEM * item, Item_Options opts)
  50. {
  51. T((T_CALLED("set_menu_opts(%p,%d)"), item, opts));
  52. opts &= ALL_ITEM_OPTS;
  53. if (opts & ~ALL_ITEM_OPTS)
  54. RETURN(E_BAD_ARGUMENT);
  55. if (item)
  56. {
  57. if (item->opt != opts)
  58. {
  59. MENU *menu = item->imenu;
  60. item->opt = opts;
  61. if ((!(opts & O_SELECTABLE)) && item->value)
  62. item->value = FALSE;
  63. if (menu && (menu->status & _POSTED))
  64. {
  65. Move_And_Post_Item(menu, item);
  66. _nc_Show_Menu(menu);
  67. }
  68. }
  69. }
  70. else
  71. _nc_Default_Item.opt = opts;
  72. RETURN(E_OK);
  73. }
  74. /*---------------------------------------------------------------------------
  75. | Facility : libnmenu
  76. | Function : int item_opts_off(ITEM *item, Item_Options opts)
  77. |
  78. | Description : Switch of the options for this item.
  79. |
  80. | Return Values : E_OK - success
  81. | E_BAD_ARGUMENT - invalid options
  82. +--------------------------------------------------------------------------*/
  83. NCURSES_EXPORT(int)
  84. item_opts_off(ITEM * item, Item_Options opts)
  85. {
  86. ITEM *citem = item; /* use a copy because set_item_opts must detect
  87. NULL item itself to adjust its behavior */
  88. T((T_CALLED("item_opts_off(%p,%d)"), item, opts));
  89. if (opts & ~ALL_ITEM_OPTS)
  90. RETURN(E_BAD_ARGUMENT);
  91. else
  92. {
  93. Normalize_Item(citem);
  94. opts = citem->opt & ~(opts & ALL_ITEM_OPTS);
  95. returnCode(set_item_opts(item, opts));
  96. }
  97. }
  98. /*---------------------------------------------------------------------------
  99. | Facility : libnmenu
  100. | Function : int item_opts_on(ITEM *item, Item_Options opts)
  101. |
  102. | Description : Switch on the options for this item.
  103. |
  104. | Return Values : E_OK - success
  105. | E_BAD_ARGUMENT - invalid options
  106. +--------------------------------------------------------------------------*/
  107. NCURSES_EXPORT(int)
  108. item_opts_on(ITEM * item, Item_Options opts)
  109. {
  110. ITEM *citem = item; /* use a copy because set_item_opts must detect
  111. NULL item itself to adjust its behavior */
  112. T((T_CALLED("item_opts_on(%p,%d)"), item, opts));
  113. opts &= ALL_ITEM_OPTS;
  114. if (opts & ~ALL_ITEM_OPTS)
  115. RETURN(E_BAD_ARGUMENT);
  116. else
  117. {
  118. Normalize_Item(citem);
  119. opts = citem->opt | opts;
  120. returnCode(set_item_opts(item, opts));
  121. }
  122. }
  123. /*---------------------------------------------------------------------------
  124. | Facility : libnmenu
  125. | Function : Item_Options item_opts(const ITEM *item)
  126. |
  127. | Description : Switch of the options for this item.
  128. |
  129. | Return Values : Items options
  130. +--------------------------------------------------------------------------*/
  131. NCURSES_EXPORT(Item_Options)
  132. item_opts(const ITEM * item)
  133. {
  134. T((T_CALLED("item_opts(%p)"), item));
  135. returnItemOpts(ALL_ITEM_OPTS & Normalize_Item(item)->opt);
  136. }
  137. /* m_item_opt.c ends here */