Lines Matching defs:item
1 /* $NetBSD: item.c,v 1.12 2012/03/21 05:33:27 matt Exp $ */
30 __RCSID("$NetBSD: item.c,v 1.12 2012/03/21 05:33:27 matt Exp $");
40 /* keep default item options for setting in new_item */
41 ITEM _menui_default_item = {
42 {NULL, 0}, /* item name struct */
43 {NULL, 0}, /* item description struct */
45 0, /* is item visible? */
46 0, /* is item selected? */
47 0, /* row item is on */
48 0, /* column item is on */
49 O_SELECTABLE, /* item options */
50 NULL, /* parent menu item is bound to */
51 -1, /* index number if item attached to a menu */
59 * Return the item visibility flag
62 item_visible(ITEM *item)
64 if (item == NULL)
66 if (item->parent == NULL)
69 return item->visible;
73 * Return the pointer to the item name
76 item_name(ITEM *item)
78 if (item == NULL)
81 return item->name.string;
85 * Return the pointer to the item description
88 item_description(ITEM *item)
90 if (item == NULL)
93 return item->description.string;
98 * just after the current item changes.
112 * Return a pointer to the item initialisation routine.
125 * before the current item changes.
183 * Set the item options. We keep a global copy of the current item options
188 set_item_opts(ITEM *item, OPTIONS opts)
190 /* selectable seems to be the only allowable item opt! */
194 if (item == NULL)
197 item->opts = opts;
202 * Set item options on.
205 item_opts_on(ITEM *item, OPTIONS opts)
210 if (item == NULL)
213 item->opts |= opts;
221 item_opts_off(ITEM *item, OPTIONS opts)
226 if (item == NULL)
229 item->opts &= ~(opts);
234 * Return the current options set in item.
237 item_opts(ITEM *item)
239 if (item == NULL)
242 return item->opts;
246 * Set the selected flag of the item iff the menu options allow it.
249 set_item_value(ITEM *param_item, int flag)
251 ITEM *item = (param_item != NULL) ? param_item : &_menui_default_item;
254 if (item->parent == NULL)
258 if ((item->parent->opts & O_ONEVALUE) == O_ONEVALUE)
261 item->selected = flag;
262 _menui_draw_item(item->parent, item->index);
267 * Return the item value of the item.
270 item_value(ITEM *item)
272 if (item == NULL)
275 return item->selected;
279 * Allocate a new item and return the pointer to the newly allocated
282 ITEM *
285 ITEM *new_one;
290 /* allocate a new item structure for ourselves */
291 if ((new_one = (ITEM *)malloc(sizeof(ITEM))) == NULL)
294 /* copy in the defaults for the item */
295 (void)memcpy(new_one, &_menui_default_item, sizeof(ITEM));
334 * Free the allocated storage associated with item.
337 free_item(ITEM *item)
339 if (item == NULL)
343 if (item->parent != NULL)
347 free(item->name.string);
348 if (item->description.length)
349 free(item->description.string);
350 free(item);
355 * Set the menu's current item to the one given.
358 set_current_item(MENU *param_menu, ITEM *item)
371 if ((i = item_index(item)) < 0)
372 /* item must not be a part of this menu */
380 * Return a pointer to the current item for the menu
382 ITEM *
395 * Return the index into the item array that matches item.
398 item_index(ITEM *item)
400 if (item == NULL)
403 return item->index;