1 /* $OpenBSD: m_item_top.c,v 1.6 2023/10/17 09:52:10 nicm Exp $ */
2
3 /****************************************************************************
4 * Copyright 2020,2021 Thomas E. Dickey *
5 * Copyright 1998-2004,2010 Free Software Foundation, Inc. *
6 * *
7 * Permission is hereby granted, free of charge, to any person obtaining a *
8 * copy of this software and associated documentation files (the *
9 * "Software"), to deal in the Software without restriction, including *
10 * without limitation the rights to use, copy, modify, merge, publish, *
11 * distribute, distribute with modifications, sublicense, and/or sell *
12 * copies of the Software, and to permit persons to whom the Software is *
13 * furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included *
16 * in all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * *
26 * Except as contained in this notice, the name(s) of the above copyright *
27 * holders shall not be used in advertising or otherwise to promote the *
28 * sale, use or other dealings in this Software without prior written *
29 * authorization. *
30 ****************************************************************************/
31
32 /****************************************************************************
33 * Author: Juergen Pfeifer, 1995,1997 *
34 ****************************************************************************/
35
36 /***************************************************************************
37 * Module m_item_top *
38 * Set and get top menus item *
39 ***************************************************************************/
40
41 #include "menu.priv.h"
42
43 MODULE_ID("$Id: m_item_top.c,v 1.6 2023/10/17 09:52:10 nicm Exp $")
44
45 /*---------------------------------------------------------------------------
46 | Facility : libnmenu
47 | Function : int set_top_row(MENU *menu, int row)
48 |
49 | Description : Makes the specified row the top row in the menu
50 |
51 | Return Values : E_OK - success
52 | E_BAD_ARGUMENT - not a menu pointer or invalid row
53 | E_NOT_CONNECTED - there are no items for the menu
54 +--------------------------------------------------------------------------*/
MENU_EXPORT(int)55 MENU_EXPORT(int)
56 set_top_row(MENU *menu, int row)
57 {
58 T((T_CALLED("set_top_row(%p,%d)"), (void *)menu, row));
59
60 if (menu)
61 {
62 if (menu->status & _IN_DRIVER)
63 RETURN(E_BAD_STATE);
64 if (menu->items == (ITEM **)0)
65 RETURN(E_NOT_CONNECTED);
66
67 if ((row < 0) || (row > (menu->rows - menu->arows)))
68 RETURN(E_BAD_ARGUMENT);
69 }
70 else
71 RETURN(E_BAD_ARGUMENT);
72
73 if (row != menu->toprow)
74 {
75 ITEM *item;
76
77 if (menu->status & _LINK_NEEDED)
78 _nc_Link_Items(menu);
79
80 item = menu->items[(menu->opt & O_ROWMAJOR) ? (row * menu->cols) : row];
81 assert(menu->pattern);
82 Reset_Pattern(menu);
83 _nc_New_TopRow_and_CurrentItem(menu, row, item);
84 }
85
86 RETURN(E_OK);
87 }
88
89 /*---------------------------------------------------------------------------
90 | Facility : libnmenu
91 | Function : int top_row(const MENU *)
92 |
93 | Description : Return the top row of the menu
94 |
95 | Return Values : The row number or ERR if there is no row
96 +--------------------------------------------------------------------------*/
97 MENU_EXPORT(int)
top_row(const MENU * menu)98 top_row(const MENU *menu)
99 {
100 T((T_CALLED("top_row(%p)"), (const void *)menu));
101 if (menu && menu->items && *(menu->items))
102 {
103 assert((menu->toprow >= 0) && (menu->toprow < menu->rows));
104 returnCode(menu->toprow);
105 }
106 else
107 returnCode(ERR);
108 }
109
110 /* m_item_top.c ends here */
111