150276Speter/**************************************************************************** 2262629Sdelphij * Copyright (c) 1998-2004,2010 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_item_cur * 3550276Speter* Set and get current menus item * 3650276Speter***************************************************************************/ 3750276Speter 3850276Speter#include "menu.priv.h" 3950276Speter 40262629SdelphijMODULE_ID("$Id: m_item_cur.c,v 1.18 2010/01/23 21:20:10 tom Exp $") 4150276Speter 4250276Speter/*--------------------------------------------------------------------------- 4350276Speter| Facility : libnmenu 4450276Speter| Function : int set_current_item(MENU *menu, const ITEM *item) 4550276Speter| 4650276Speter| Description : Make the item the current item 4750276Speter| 4850276Speter| Return Values : E_OK - success 4950276Speter+--------------------------------------------------------------------------*/ 5076726SpeterNCURSES_EXPORT(int) 51166124Srafanset_current_item(MENU * menu, ITEM * item) 5250276Speter{ 53262629Sdelphij T((T_CALLED("set_current_item(%p,%p)"), (void *)menu, (void *)item)); 54166124Srafan 55166124Srafan if (menu && item && (item->imenu == menu)) 5650276Speter { 57166124Srafan if (menu->status & _IN_DRIVER) 5850276Speter RETURN(E_BAD_STATE); 59166124Srafan 60166124Srafan assert(menu->curitem); 6150276Speter if (item != menu->curitem) 6250276Speter { 6350276Speter if (menu->status & _LINK_NEEDED) 6450276Speter { 6550276Speter /* 6650276Speter * Items are available, but they are not linked together. 6750276Speter * So we have to link here. 6850276Speter */ 6950276Speter _nc_Link_Items(menu); 7050276Speter } 7150276Speter assert(menu->pattern); 7250276Speter Reset_Pattern(menu); 7350276Speter /* adjust the window to make item visible and update the menu */ 74166124Srafan Adjust_Current_Item(menu, menu->toprow, item); 7550276Speter } 7650276Speter } 7750276Speter else 7850276Speter RETURN(E_BAD_ARGUMENT); 79166124Srafan 8050276Speter RETURN(E_OK); 8150276Speter} 8250276Speter 8350276Speter/*--------------------------------------------------------------------------- 8450276Speter| Facility : libnmenu 8550276Speter| Function : ITEM *current_item(const MENU *menu) 8650276Speter| 8750276Speter| Description : Return the menus current item 8850276Speter| 8950276Speter| Return Values : Item pointer or NULL if failure 9050276Speter+--------------------------------------------------------------------------*/ 9176726SpeterNCURSES_EXPORT(ITEM *) 92166124Srafancurrent_item(const MENU * menu) 9350276Speter{ 94262629Sdelphij T((T_CALLED("current_item(%p)"), (const void *)menu)); 95166124Srafan returnItem((menu && menu->items) ? menu->curitem : (ITEM *) 0); 9650276Speter} 9750276Speter 9850276Speter/*--------------------------------------------------------------------------- 9950276Speter| Facility : libnmenu 10050276Speter| Function : int item_index(const ITEM *) 10150276Speter| 10250276Speter| Description : Return the logical index of this item. 10350276Speter| 10450276Speter| Return Values : The index or ERR if this is an invalid item pointer 10550276Speter+--------------------------------------------------------------------------*/ 10676726SpeterNCURSES_EXPORT(int) 107166124Srafanitem_index(const ITEM * item) 10850276Speter{ 109262629Sdelphij T((T_CALLED("item_index(%p)"), (const void *)item)); 110166124Srafan returnCode((item && item->imenu) ? item->index : ERR); 11150276Speter} 11250276Speter 11350276Speter/* m_item_cur.c ends here */ 114