150276Speter/****************************************************************************
2166124Srafan * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
30166124Srafan *   Author:  Juergen Pfeifer, 1995,1997                                    *
3150276Speter ****************************************************************************/
3250276Speter
3350276Speter/***************************************************************************
3450276Speter* Module m_items                                                           *
3550276Speter* Connect and disconnect items to and from menus                           *
3650276Speter***************************************************************************/
3750276Speter
3850276Speter#include "menu.priv.h"
3950276Speter
40166124SrafanMODULE_ID("$Id: m_items.c,v 1.16 2005/01/16 01:02:23 tom Exp $")
4150276Speter
4250276Speter/*---------------------------------------------------------------------------
4350276Speter|   Facility      :  libnmenu
4450276Speter|   Function      :  int set_menu_items(MENU *menu, ITEM **items)
4550276Speter|
4650276Speter|   Description   :  Sets the item pointer array connected to menu.
4750276Speter|
4850276Speter|   Return Values :  E_OK           - success
4950276Speter|                    E_POSTED       - menu is already posted
5050276Speter|                    E_CONNECTED    - one or more items are already connected
5150276Speter|                                     to another menu.
5250276Speter|                    E_BAD_ARGUMENT - An incorrect menu or item array was
5350276Speter|                                     passed to the function
5450276Speter+--------------------------------------------------------------------------*/
5576726SpeterNCURSES_EXPORT(int)
56166124Srafanset_menu_items(MENU * menu, ITEM ** items)
5750276Speter{
58166124Srafan  T((T_CALLED("set_menu_items(%p,%p)"), menu, items));
59166124Srafan
6050276Speter  if (!menu || (items && !(*items)))
6150276Speter    RETURN(E_BAD_ARGUMENT);
62166124Srafan
63166124Srafan  if (menu->status & _POSTED)
6450276Speter    RETURN(E_POSTED);
65166124Srafan
6650276Speter  if (menu->items)
6750276Speter    _nc_Disconnect_Items(menu);
68166124Srafan
6950276Speter  if (items)
7050276Speter    {
71166124Srafan      if (!_nc_Connect_Items(menu, items))
7250276Speter	RETURN(E_CONNECTED);
7350276Speter    }
74166124Srafan
7550276Speter  menu->items = items;
7650276Speter  RETURN(E_OK);
77166124Srafan}
7850276Speter
7950276Speter/*---------------------------------------------------------------------------
8050276Speter|   Facility      :  libnmenu
8150276Speter|   Function      :  ITEM **menu_items(const MENU *menu)
8250276Speter|
83166124Srafan|   Description   :  Returns a pointer to the item pointer array of the menu
8450276Speter|
8550276Speter|   Return Values :  NULL on error
8650276Speter+--------------------------------------------------------------------------*/
8776726SpeterNCURSES_EXPORT(ITEM **)
88166124Srafanmenu_items(const MENU * menu)
8950276Speter{
90166124Srafan  T((T_CALLED("menu_items(%p)"), menu));
91166124Srafan  returnItemPtr(menu ? menu->items : (ITEM **) 0);
9250276Speter}
9350276Speter
9450276Speter/*---------------------------------------------------------------------------
9550276Speter|   Facility      :  libnmenu
9650276Speter|   Function      :  int item_count(const MENU *menu)
9750276Speter|
9850276Speter|   Description   :  Get the number of items connected to the menu. If the
9950276Speter|                    menu pointer is NULL we return -1.
10050276Speter|
10150276Speter|   Return Values :  Number of items or -1 to indicate error.
10250276Speter+--------------------------------------------------------------------------*/
10376726SpeterNCURSES_EXPORT(int)
104166124Srafanitem_count(const MENU * menu)
10550276Speter{
106166124Srafan  T((T_CALLED("item_count(%p)"), menu));
107166124Srafan  returnCode(menu ? menu->nitems : -1);
10850276Speter}
10950276Speter
11050276Speter/* m_items.c ends here */
111