1 /* $OpenBSD: m_items.c,v 1.3 1997/12/03 05:31:23 millert Exp $ */ 2 3 /*-----------------------------------------------------------------------------+ 4 | The ncurses menu library is Copyright (C) 1995-1997 | 5 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> | 6 | All Rights Reserved. | 7 | | 8 | Permission to use, copy, modify, and distribute this software and its | 9 | documentation for any purpose and without fee is hereby granted, provided | 10 | that the above copyright notice appear in all copies and that both that | 11 | copyright notice and this permission notice appear in supporting | 12 | documentation, and that the name of the above listed copyright holder(s) not | 13 | be used in advertising or publicity pertaining to distribution of the | 14 | software without specific, written prior permission. | 15 | | 16 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO | 17 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- | 18 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR | 19 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- | 20 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | 21 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH | 22 | THE USE OR PERFORMANCE OF THIS SOFTWARE. | 23 +-----------------------------------------------------------------------------*/ 24 25 /*************************************************************************** 26 * Module m_items * 27 * Connect and disconnect items to and from menus * 28 ***************************************************************************/ 29 30 #include "menu.priv.h" 31 32 MODULE_ID("Id: m_items.c,v 1.5 1997/10/21 08:44:31 juergen Exp $") 33 34 /*--------------------------------------------------------------------------- 35 | Facility : libnmenu 36 | Function : int set_menu_items(MENU *menu, ITEM **items) 37 | 38 | Description : Sets the item pointer array connected to menu. 39 | 40 | Return Values : E_OK - success 41 | E_POSTED - menu is already posted 42 | E_CONNECTED - one or more items are already connected 43 | to another menu. 44 | E_BAD_ARGUMENT - An incorrect menu or item array was 45 | passed to the function 46 +--------------------------------------------------------------------------*/ 47 int set_menu_items(MENU * menu, ITEM ** items) 48 { 49 if (!menu || (items && !(*items))) 50 RETURN(E_BAD_ARGUMENT); 51 52 if ( menu->status & _POSTED ) 53 RETURN(E_POSTED); 54 55 if (menu->items) 56 _nc_Disconnect_Items(menu); 57 58 if (items) 59 { 60 if(!_nc_Connect_Items( menu, items )) 61 RETURN(E_CONNECTED); 62 } 63 64 menu->items = items; 65 RETURN(E_OK); 66 } 67 68 /*--------------------------------------------------------------------------- 69 | Facility : libnmenu 70 | Function : ITEM **menu_items(const MENU *menu) 71 | 72 | Description : Returns a pointer to the item pointer arry of the menu 73 | 74 | Return Values : NULL on error 75 +--------------------------------------------------------------------------*/ 76 ITEM **menu_items(const MENU *menu) 77 { 78 return(menu ? menu->items : (ITEM **)0); 79 } 80 81 /*--------------------------------------------------------------------------- 82 | Facility : libnmenu 83 | Function : int item_count(const MENU *menu) 84 | 85 | Description : Get the number of items connected to the menu. If the 86 | menu pointer is NULL we return -1. 87 | 88 | Return Values : Number of items or -1 to indicate error. 89 +--------------------------------------------------------------------------*/ 90 int item_count(const MENU *menu) 91 { 92 return(menu ? menu->nitems : -1); 93 } 94 95 /* m_items.c ends here */ 96