m_items.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /****************************************************************************
  2. * Copyright (c) 1998-2004,2005 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_items *
  33. * Connect and disconnect items to and from menus *
  34. ***************************************************************************/
  35. #include "menu.priv.h"
  36. MODULE_ID("$Id: m_items.c,v 1.16 2005/01/16 01:02:23 tom Exp $")
  37. /*---------------------------------------------------------------------------
  38. | Facility : libnmenu
  39. | Function : int set_menu_items(MENU *menu, ITEM **items)
  40. |
  41. | Description : Sets the item pointer array connected to menu.
  42. |
  43. | Return Values : E_OK - success
  44. | E_POSTED - menu is already posted
  45. | E_CONNECTED - one or more items are already connected
  46. | to another menu.
  47. | E_BAD_ARGUMENT - An incorrect menu or item array was
  48. | passed to the function
  49. +--------------------------------------------------------------------------*/
  50. NCURSES_EXPORT(int)
  51. set_menu_items(MENU * menu, ITEM ** items)
  52. {
  53. T((T_CALLED("set_menu_items(%p,%p)"), menu, items));
  54. if (!menu || (items && !(*items)))
  55. RETURN(E_BAD_ARGUMENT);
  56. if (menu->status & _POSTED)
  57. RETURN(E_POSTED);
  58. if (menu->items)
  59. _nc_Disconnect_Items(menu);
  60. if (items)
  61. {
  62. if (!_nc_Connect_Items(menu, items))
  63. RETURN(E_CONNECTED);
  64. }
  65. menu->items = items;
  66. RETURN(E_OK);
  67. }
  68. /*---------------------------------------------------------------------------
  69. | Facility : libnmenu
  70. | Function : ITEM **menu_items(const MENU *menu)
  71. |
  72. | Description : Returns a pointer to the item pointer array of the menu
  73. |
  74. | Return Values : NULL on error
  75. +--------------------------------------------------------------------------*/
  76. NCURSES_EXPORT(ITEM **)
  77. menu_items(const MENU * menu)
  78. {
  79. T((T_CALLED("menu_items(%p)"), menu));
  80. returnItemPtr(menu ? menu->items : (ITEM **) 0);
  81. }
  82. /*---------------------------------------------------------------------------
  83. | Facility : libnmenu
  84. | Function : int item_count(const MENU *menu)
  85. |
  86. | Description : Get the number of items connected to the menu. If the
  87. | menu pointer is NULL we return -1.
  88. |
  89. | Return Values : Number of items or -1 to indicate error.
  90. +--------------------------------------------------------------------------*/
  91. NCURSES_EXPORT(int)
  92. item_count(const MENU * menu)
  93. {
  94. T((T_CALLED("item_count(%p)"), menu));
  95. returnCode(menu ? menu->nitems : -1);
  96. }
  97. /* m_items.c ends here */