1 /* $OpenBSD: m_item_cur.c,v 1.3 1997/12/03 05:31:19 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_item_cur * 27 * Set and get current menus item * 28 ***************************************************************************/ 29 30 #include "menu.priv.h" 31 32 MODULE_ID("Id: m_item_cur.c,v 1.8 1997/10/21 08:44:31 juergen Exp $") 33 34 /*--------------------------------------------------------------------------- 35 | Facility : libnmenu 36 | Function : int set_current_item(MENU *menu, const ITEM *item) 37 | 38 | Description : Make the item the current item 39 | 40 | Return Values : E_OK - success 41 +--------------------------------------------------------------------------*/ 42 int set_current_item(MENU * menu, ITEM * item) 43 { 44 if (menu && item && (item->imenu==menu)) 45 { 46 if ( menu->status & _IN_DRIVER ) 47 RETURN(E_BAD_STATE); 48 49 assert( menu->curitem ); 50 if (item != menu->curitem) 51 { 52 if (menu->status & _LINK_NEEDED) 53 { 54 /* 55 * Items are available, but they are not linked together. 56 * So we have to link here. 57 */ 58 _nc_Link_Items(menu); 59 } 60 assert(menu->pattern); 61 Reset_Pattern(menu); 62 /* adjust the window to make item visible and update the menu */ 63 Adjust_Current_Item(menu,menu->toprow,item); 64 } 65 } 66 else 67 RETURN(E_BAD_ARGUMENT); 68 69 RETURN(E_OK); 70 } 71 72 /*--------------------------------------------------------------------------- 73 | Facility : libnmenu 74 | Function : ITEM *current_item(const MENU *menu) 75 | 76 | Description : Return the menus current item 77 | 78 | Return Values : Item pointer or NULL if failure 79 +--------------------------------------------------------------------------*/ 80 ITEM *current_item(const MENU * menu) 81 { 82 return (menu && menu->items) ? menu->curitem : (ITEM *)0; 83 } 84 85 /*--------------------------------------------------------------------------- 86 | Facility : libnmenu 87 | Function : int item_index(const ITEM *) 88 | 89 | Description : Return the logical index of this item. 90 | 91 | Return Values : The index or ERR if this is an invalid item pointer 92 +--------------------------------------------------------------------------*/ 93 int item_index(const ITEM *item) 94 { 95 return (item && item->imenu) ? item->index : ERR; 96 } 97 98 /* m_item_cur.c ends here */ 99