1132720Skan/* $OpenBSD: m_items.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */ 2132720Skan 3169691Skan/**************************************************************************** 4132720Skan * Copyright 2020,2021 Thomas E. Dickey * 5132720Skan * Copyright 1998-2005,2010 Free Software Foundation, Inc. * 6132720Skan * * 7132720Skan * Permission is hereby granted, free of charge, to any person obtaining a * 8132720Skan * copy of this software and associated documentation files (the * 9132720Skan * "Software"), to deal in the Software without restriction, including * 10132720Skan * without limitation the rights to use, copy, modify, merge, publish, * 11132720Skan * distribute, distribute with modifications, sublicense, and/or sell * 12132720Skan * copies of the Software, and to permit persons to whom the Software is * 13132720Skan * furnished to do so, subject to the following conditions: * 14132720Skan * * 15132720Skan * The above copyright notice and this permission notice shall be included * 16132720Skan * in all copies or substantial portions of the Software. * 17132720Skan * * 18132720Skan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19169691Skan * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20132720Skan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21132720Skan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22132720Skan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23132720Skan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24132720Skan * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25132720Skan * * 26132720Skan * Except as contained in this notice, the name(s) of the above copyright * 27132720Skan * holders shall not be used in advertising or otherwise to promote the * 28132720Skan * sale, use or other dealings in this Software without prior written * 29132720Skan * authorization. * 30132720Skan ****************************************************************************/ 31169691Skan 32169691Skan/**************************************************************************** 33169691Skan * Author: Juergen Pfeifer, 1995,1997 * 34169691Skan ****************************************************************************/ 35132720Skan 36132720Skan/*************************************************************************** 37132720Skan* Module m_items * 38132720Skan* Connect and disconnect items to and from menus * 39132720Skan***************************************************************************/ 40132720Skan 41169691Skan#include "menu.priv.h" 42132720Skan 43169691SkanMODULE_ID("$Id: m_items.c,v 1.8 2023/10/17 09:52:10 nicm Exp $") 44169691Skan 45132720Skan/*--------------------------------------------------------------------------- 46132720Skan| Facility : libnmenu 47132720Skan| Function : int set_menu_items(MENU *menu, ITEM **items) 48132720Skan| 49132720Skan| Description : Sets the item pointer array connected to menu. 50169691Skan| 51132720Skan| Return Values : E_OK - success 52132720Skan| E_POSTED - menu is already posted 53132720Skan| E_CONNECTED - one or more items are already connected 54169691Skan| to another menu. 55132720Skan| E_BAD_ARGUMENT - An incorrect menu or item array was 56132720Skan| passed to the function 57132720Skan+--------------------------------------------------------------------------*/ 58132720SkanMENU_EXPORT(int) 59132720Skanset_menu_items(MENU *menu, ITEM **items) 60132720Skan{ 61132720Skan T((T_CALLED("set_menu_items(%p,%p)"), (void *)menu, (void *)items)); 62132720Skan 63132720Skan if (!menu || (items && !(*items))) 64132720Skan RETURN(E_BAD_ARGUMENT); 65132720Skan 66132720Skan if (menu->status & _POSTED) 67132720Skan RETURN(E_POSTED); 68132720Skan 69132720Skan if (menu->items) 70132720Skan _nc_Disconnect_Items(menu); 71132720Skan 72132720Skan if (items) 73132720Skan { 74132720Skan if (!_nc_Connect_Items(menu, items)) 75132720Skan RETURN(E_CONNECTED); 76132720Skan } 77132720Skan 78132720Skan menu->items = items; 79132720Skan RETURN(E_OK); 80132720Skan} 81132720Skan 82132720Skan/*--------------------------------------------------------------------------- 83132720Skan| Facility : libnmenu 84132720Skan| Function : ITEM **menu_items(const MENU *menu) 85132720Skan| 86132720Skan| Description : Returns a pointer to the item pointer array of the menu 87132720Skan| 88132720Skan| Return Values : NULL on error 89132720Skan+--------------------------------------------------------------------------*/ 90132720SkanMENU_EXPORT(ITEM **) 91132720Skanmenu_items(const MENU *menu) 92132720Skan{ 93132720Skan T((T_CALLED("menu_items(%p)"), (const void *)menu)); 94132720Skan returnItemPtr(menu ? menu->items : (ITEM **)0); 95132720Skan} 96132720Skan 97132720Skan/*--------------------------------------------------------------------------- 98132720Skan| Facility : libnmenu 99132720Skan| Function : int item_count(const MENU *menu) 100132720Skan| 101132720Skan| Description : Get the number of items connected to the menu. If the 102132720Skan| menu pointer is NULL we return -1. 103132720Skan| 104132720Skan| Return Values : Number of items or -1 to indicate error. 105132720Skan+--------------------------------------------------------------------------*/ 106132720SkanMENU_EXPORT(int) 107132720Skanitem_count(const MENU *menu) 108132720Skan{ 109132720Skan T((T_CALLED("item_count(%p)"), (const void *)menu)); 110132720Skan returnCode(menu ? menu->nitems : -1); 111132720Skan} 112132720Skan 113132720Skan/* m_items.c ends here */ 114132720Skan