2 * Copyright Geoff Levand <geoff@infradead.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #if !defined(_PBT_MENU_H)
21 #include "list/list.h"
22 #include "types/types.h"
28 * struct pbt_item - A menu item.
33 struct list_item list;
35 struct pbt_menu *menu; // convinence pointer
36 struct pbt_client *pbt_client; // convinence pointer
38 twin_window_t *window;
39 twin_pixmap_t *pixmap_idle;
40 twin_pixmap_t *pixmap_selected;
41 twin_pixmap_t *pixmap_active;
43 struct pbt_menu *sub_menu;
44 struct pbt_item *selected_item;
46 int (*on_execute)(struct pbt_item *item);
47 int (*on_edit)(struct pbt_item *item);
50 struct device *pb_device;
51 struct boot_option *pb_opt;
56 struct pbt_item *pbt_item_create(struct pbt_menu *menu, const char *name,
57 unsigned int position, const char *icon_filename, const char *title,
60 static inline struct pbt_item *pbt_item_create_reduced(struct pbt_menu *menu,
61 const char *name, unsigned int position, const char *icon_filename)
63 return pbt_item_create(menu, name, position, icon_filename, NULL,
67 static inline const char *pbt_item_name(const struct pbt_item *item)
69 return item->window->name;
72 #define pbt_dump_item(_i) _pbt_dump_item(_i, __func__, __LINE__)
73 void _pbt_dump_item(const struct pbt_item* item, const char *func,
76 struct pbt_text_layout {
78 unsigned int font_size;
81 struct pbt_menu_layout {
82 unsigned int item_height;
83 unsigned int item_space;
84 unsigned int text_space;
85 //unsigned int icon_height;
86 //unsigned int icon_width;
87 struct pbt_text_layout title;
88 struct pbt_text_layout text;
92 * struct pbt_menu - A twin menu screen.
96 struct pbt_scr *scr; // convinence pointer
97 struct pbt_menu *parent;
98 twin_window_t *window;
99 twin_pixmap_t *pixmap;
101 struct pbt_border border;
102 twin_argb32_t background_color;
103 struct pbt_menu_layout layout;
105 struct list* item_list;
106 unsigned int n_items;
107 uint32_t default_item_hash;
110 struct pbt_item *selected;
111 int (*on_open)(struct pbt_menu *menu);
114 struct pbt_menu *pbt_menu_create(void *talloc_ctx, const char *name,
115 struct pbt_scr *scr, struct pbt_menu *parent, const struct pbt_quad *q,
116 const struct pbt_menu_layout *layout);
117 void pbt_menu_set_focus(struct pbt_menu *menu, int focus);
118 void pbt_menu_set_selected(struct pbt_menu *menu, struct pbt_item *item);
119 struct pbt_quad *pbt_menu_get_item_quad(const struct pbt_menu *menu,
120 unsigned int pos, struct pbt_quad *q);
121 void pbt_menu_hide(struct pbt_menu *menu);
122 void pbt_menu_show(struct pbt_menu *menu, int hide);
124 static inline const char *pbt_menu_name(const struct pbt_menu *menu)
126 return menu->window->name;
129 static inline struct pbt_menu *pbt_menu_from_window(twin_window_t *window)
131 struct pbt_menu *menu = window->client_data;
137 static inline struct pbt_item *pbt_item_from_window(twin_window_t *window)
139 struct pbt_item *item = window->client_data;
145 static inline int pbt_item_is_selected(const struct pbt_item* item)
147 return item == item->menu->selected;
150 static inline void pbt_item_set_as_selected(struct pbt_item* item)
152 pbt_menu_set_selected(item->menu, item);
155 int pbt_item_editor(struct pbt_item *item);
157 static inline void pbt_item_redraw(struct pbt_item *item)
159 pbt_window_redraw(item->window);
162 static inline void pbt_menu_redraw(struct pbt_menu *menu)
164 pbt_window_redraw(menu->window);