1*c7ef0cfcSnicm /* $OpenBSD: m_items.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */
29f1aa62bSmillert
3457960bfSmillert /****************************************************************************
4*c7ef0cfcSnicm * Copyright 2020,2021 Thomas E. Dickey *
5*c7ef0cfcSnicm * Copyright 1998-2005,2010 Free Software Foundation, Inc. *
6457960bfSmillert * *
7457960bfSmillert * Permission is hereby granted, free of charge, to any person obtaining a *
8457960bfSmillert * copy of this software and associated documentation files (the *
9457960bfSmillert * "Software"), to deal in the Software without restriction, including *
10457960bfSmillert * without limitation the rights to use, copy, modify, merge, publish, *
11457960bfSmillert * distribute, distribute with modifications, sublicense, and/or sell *
12457960bfSmillert * copies of the Software, and to permit persons to whom the Software is *
13457960bfSmillert * furnished to do so, subject to the following conditions: *
14457960bfSmillert * *
15457960bfSmillert * The above copyright notice and this permission notice shall be included *
16457960bfSmillert * in all copies or substantial portions of the Software. *
17457960bfSmillert * *
18457960bfSmillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19457960bfSmillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20457960bfSmillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21457960bfSmillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22457960bfSmillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23457960bfSmillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24457960bfSmillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25457960bfSmillert * *
26457960bfSmillert * Except as contained in this notice, the name(s) of the above copyright *
27457960bfSmillert * holders shall not be used in advertising or otherwise to promote the *
28457960bfSmillert * sale, use or other dealings in this Software without prior written *
29457960bfSmillert * authorization. *
30457960bfSmillert ****************************************************************************/
31457960bfSmillert
32457960bfSmillert /****************************************************************************
3381d8c4e1Snicm * Author: Juergen Pfeifer, 1995,1997 *
34457960bfSmillert ****************************************************************************/
35c166cd22Stholo
36c166cd22Stholo /***************************************************************************
379f1aa62bSmillert * Module m_items *
38c166cd22Stholo * Connect and disconnect items to and from menus *
39c166cd22Stholo ***************************************************************************/
40c166cd22Stholo
41c166cd22Stholo #include "menu.priv.h"
42c166cd22Stholo
43*c7ef0cfcSnicm MODULE_ID("$Id: m_items.c,v 1.8 2023/10/17 09:52:10 nicm Exp $")
440107aba4Smillert
45c166cd22Stholo /*---------------------------------------------------------------------------
46c166cd22Stholo | Facility : libnmenu
47c166cd22Stholo | Function : int set_menu_items(MENU *menu, ITEM **items)
48c166cd22Stholo |
49c166cd22Stholo | Description : Sets the item pointer array connected to menu.
50c166cd22Stholo |
51c166cd22Stholo | Return Values : E_OK - success
52c166cd22Stholo | E_POSTED - menu is already posted
53c166cd22Stholo | E_CONNECTED - one or more items are already connected
54c166cd22Stholo | to another menu.
55c166cd22Stholo | E_BAD_ARGUMENT - An incorrect menu or item array was
56c166cd22Stholo | passed to the function
57c166cd22Stholo +--------------------------------------------------------------------------*/
MENU_EXPORT(int)58*c7ef0cfcSnicm MENU_EXPORT(int)
5984af20ceSmillert set_menu_items(MENU *menu, ITEM **items)
60c166cd22Stholo {
61*c7ef0cfcSnicm T((T_CALLED("set_menu_items(%p,%p)"), (void *)menu, (void *)items));
6281d8c4e1Snicm
63c166cd22Stholo if (!menu || (items && !(*items)))
64c166cd22Stholo RETURN(E_BAD_ARGUMENT);
65c166cd22Stholo
66c166cd22Stholo if (menu->status & _POSTED)
67c166cd22Stholo RETURN(E_POSTED);
68c166cd22Stholo
69c166cd22Stholo if (menu->items)
70c166cd22Stholo _nc_Disconnect_Items(menu);
71c166cd22Stholo
72c166cd22Stholo if (items)
73c166cd22Stholo {
74c166cd22Stholo if (!_nc_Connect_Items(menu, items))
75c166cd22Stholo RETURN(E_CONNECTED);
76c166cd22Stholo }
77c166cd22Stholo
78c166cd22Stholo menu->items = items;
79c166cd22Stholo RETURN(E_OK);
80c166cd22Stholo }
81c166cd22Stholo
82c166cd22Stholo /*---------------------------------------------------------------------------
83c166cd22Stholo | Facility : libnmenu
84c166cd22Stholo | Function : ITEM **menu_items(const MENU *menu)
85c166cd22Stholo |
8681d8c4e1Snicm | Description : Returns a pointer to the item pointer array of the menu
87c166cd22Stholo |
88c166cd22Stholo | Return Values : NULL on error
89c166cd22Stholo +--------------------------------------------------------------------------*/
90*c7ef0cfcSnicm MENU_EXPORT(ITEM **)
menu_items(const MENU * menu)9184af20ceSmillert menu_items(const MENU *menu)
92c166cd22Stholo {
93*c7ef0cfcSnicm T((T_CALLED("menu_items(%p)"), (const void *)menu));
9481d8c4e1Snicm returnItemPtr(menu ? menu->items : (ITEM **)0);
95c166cd22Stholo }
96c166cd22Stholo
97c166cd22Stholo /*---------------------------------------------------------------------------
98c166cd22Stholo | Facility : libnmenu
99c166cd22Stholo | Function : int item_count(const MENU *menu)
100c166cd22Stholo |
101c166cd22Stholo | Description : Get the number of items connected to the menu. If the
102c166cd22Stholo | menu pointer is NULL we return -1.
103c166cd22Stholo |
104c166cd22Stholo | Return Values : Number of items or -1 to indicate error.
105c166cd22Stholo +--------------------------------------------------------------------------*/
106*c7ef0cfcSnicm MENU_EXPORT(int)
item_count(const MENU * menu)10784af20ceSmillert item_count(const MENU *menu)
108c166cd22Stholo {
109*c7ef0cfcSnicm T((T_CALLED("item_count(%p)"), (const void *)menu));
11081d8c4e1Snicm returnCode(menu ? menu->nitems : -1);
111c166cd22Stholo }
112c166cd22Stholo
113c166cd22Stholo /* m_items.c ends here */
114