2 * Copyright (C) 2009 Sony Computer Entertainment Inc.
3 * Copyright 2009 Sony Corp.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #if !defined(_PB_NC_MENU_H)
24 #include <linux/input.h> /* This must be included before ncurses.h */
25 #if defined HAVE_NCURSESW_MENU_H
26 # include <ncursesw/menu.h>
27 #elif defined HAVE_NCURSES_MENU_H
28 # include <ncurses/menu.h>
29 #elif defined HAVE_MENU_H
32 # error "Curses menu.h not found."
36 #include "types/types.h"
42 * struct pmenu_item - Hold the state of a single menu item.
43 * @i_sig: Signature for callback type checking, should be pmenu_item_sig.
44 * @nci: The ncurses menu item instance for this item.
52 void (*on_edit)(struct pmenu_item *item);
53 int (*on_execute)(struct pmenu_item *item);
56 int pmenu_item_update(struct pmenu_item *item, const char *name);
57 struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name);
58 struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
59 struct boot_option *opt);
60 void pmenu_item_insert(struct pmenu *menu, struct pmenu_item *item,
62 void pmenu_item_add(struct pmenu *menu, struct pmenu_item *item,
63 unsigned int insert_pt);
64 void pmenu_item_delete(struct pmenu_item *item);
66 static inline struct pmenu_item *pmenu_item_from_arg(void *arg)
68 struct pmenu_item *item = (struct pmenu_item *)arg;
70 assert(item->i_sig == pb_item_sig);
74 static inline struct cui_opt_data *cod_from_item(struct pmenu_item *item)
79 typedef int (*hot_key_fn)(struct pmenu *menu, struct pmenu_item *item, int c);
81 int pmenu_main_hot_keys(struct pmenu *menu, struct pmenu_item *item, int c);
84 * struct pmenu - Data structure defining complete menu.
85 * @insert_pt: Index in nc item array.
86 * @ncm: The ncurses menu instance for this menu.
93 unsigned int item_count;
94 unsigned int insert_pt;
95 const char *help_title;
96 const struct help_text *help_text;
98 unsigned int n_hot_keys;
99 void (*on_exit)(struct pmenu *menu);
100 void (*on_new)(struct pmenu *menu);
103 struct pmenu *pmenu_init(void *ui_ctx, unsigned int item_count,
104 void (*on_exit)(struct pmenu *));
105 int pmenu_setup(struct pmenu *menu);
106 unsigned int pmenu_grow(struct pmenu *menu, unsigned int count);
107 int pmenu_remove(struct pmenu *menu, struct pmenu_item *item);
108 struct pmenu_item *pmenu_find_selected(struct pmenu *menu);
110 /* convenience routines */
112 int pmenu_exit_cb(struct pmenu_item *item);
114 static inline struct pmenu *pmenu_from_scr(struct nc_scr *scr)
118 assert(scr->sig == pb_pmenu_sig);
119 pmenu = (struct pmenu *)((char *)scr
120 - (size_t)&((struct pmenu *)0)->scr);
121 assert(pmenu->scr.sig == pb_pmenu_sig);
128 static inline void pmenu_dump_item(const ITEM *item)
130 pb_debug("%p %s\n", item, (item ? item->name.str : "(null)"));
133 static inline void pmenu_dump_items(ITEM *const *items, unsigned int count)
137 for (i = 0; i < count; i++)
138 pb_debug("%u: %p %s\n", i, items[i],
139 (items[i] ? items[i]->name.str : "(null)"));