1 /*-----------------------------------------------------------------------------+
2 | The ncurses menu library is Copyright (C) 1995-1997 |
3 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> |
4 | All Rights Reserved. |
6 | Permission to use, copy, modify, and distribute this software and its |
7 | documentation for any purpose and without fee is hereby granted, provided |
8 | that the above copyright notice appear in all copies and that both that |
9 | copyright notice and this permission notice appear in supporting |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the |
12 | software without specific, written prior permission. |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
21 +-----------------------------------------------------------------------------*/
23 /***************************************************************************
24 * Module menu_item_cur *
25 * Set and get current menus item *
26 ***************************************************************************/
28 #include "menu.priv.h"
30 MODULE_ID("$Id: m_item_cur.c,v 1.7 1997/05/01 16:47:26 juergen Exp $")
32 /*---------------------------------------------------------------------------
34 | Function : int set_current_item(MENU *menu, const ITEM *item)
36 | Description : Make the item the current item
38 | Return Values : E_OK - success
39 +--------------------------------------------------------------------------*/
40 int set_current_item(MENU * menu, ITEM * item)
42 if (menu && item && (item->imenu==menu))
44 if ( menu->status & _IN_DRIVER )
47 assert( menu->curitem );
48 if (item != menu->curitem)
50 if (menu->status & _LINK_NEEDED)
53 * Items are available, but they are not linked together.
54 * So we have to link here.
58 assert(menu->pattern);
60 /* adjust the window to make item visible and update the menu */
61 Adjust_Current_Item(menu,menu->toprow,item);
65 RETURN(E_BAD_ARGUMENT);
70 /*---------------------------------------------------------------------------
72 | Function : ITEM *current_item(const MENU *menu)
74 | Description : Return the menus current item
76 | Return Values : Item pointer or NULL if failure
77 +--------------------------------------------------------------------------*/
78 ITEM *current_item(const MENU * menu)
80 return (menu && menu->items) ? menu->curitem : (ITEM *)0;
83 /*---------------------------------------------------------------------------
85 | Function : int item_index(const ITEM *)
87 | Description : Return the logical index of this item.
89 | Return Values : The index or ERR if this is an invalid item pointer
90 +--------------------------------------------------------------------------*/
91 int item_index(const ITEM *item)
93 return (item && item->imenu) ? item->index : ERR;
96 /*---------------------------------------------------------------------------
98 | Function : int set_top_row(MENU *menu, int row)
100 | Description : Makes the speified row the top row in the menu
102 | Return Values : E_OK - success
103 | E_BAD_ARGUMENT - not a menu pointer or invalid row
104 | E_NOT_CONNECTED - there are no items for the menu
105 +--------------------------------------------------------------------------*/
106 int set_top_row(MENU * menu, int row)
112 if ( menu->status & _IN_DRIVER )
114 if (menu->items == (ITEM **)0)
115 RETURN(E_NOT_CONNECTED);
117 if ((row<0) || (row > (menu->rows - menu->arows)))
118 RETURN(E_BAD_ARGUMENT);
121 RETURN(E_BAD_ARGUMENT);
123 if (row != menu->toprow)
125 if (menu->status & _LINK_NEEDED)
126 _nc_Link_Items(menu);
128 item = menu->items[ (menu->opt&O_ROWMAJOR) ? (row*menu->cols) : row ];
129 assert(menu->pattern);
131 _nc_New_TopRow_and_CurrentItem(menu, row, item);
137 /*---------------------------------------------------------------------------
138 | Facility : libnmenu
139 | Function : int top_row(const MENU *)
141 | Description : Return the top row of the menu
143 | Return Values : The row number or ERR if there is no row
144 +--------------------------------------------------------------------------*/
145 int top_row(const MENU * menu)
147 if (menu && menu->items && *(menu->items))
149 assert( (menu->toprow>=0) && (menu->toprow < menu->rows) );
156 /* m_item_cur.c ends here */