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 "pb-protocol/pb-protocol.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;
45 int (*on_execute)(struct pbt_item *item);
46 int (*on_edit)(struct pbt_item *item);
49 struct device *pb_device;
50 struct boot_option *pb_opt;
55 struct pbt_item *pbt_item_create(struct pbt_menu *menu, const char *name,
56 unsigned int position, const char *icon_filename, const char *title,
59 static inline struct pbt_item *pbt_item_create_reduced(struct pbt_menu *menu,
60 const char *name, unsigned int position, const char *icon_filename)
62 return pbt_item_create(menu, name, position, icon_filename, NULL,
66 static inline const char *pbt_item_name(const struct pbt_item *item)
68 return item->window->name;
71 #define pbt_dump_item(_i) _pbt_dump_item(_i, __func__, __LINE__)
72 void _pbt_dump_item(const struct pbt_item* item, const char *func,
75 struct pbt_text_layout {
77 unsigned int font_size;
80 struct pbt_menu_layout {
81 unsigned int item_height;
82 unsigned int item_space;
83 unsigned int text_space;
84 //unsigned int icon_height;
85 //unsigned int icon_width;
86 struct pbt_text_layout title;
87 struct pbt_text_layout text;
91 * struct pbt_menu - A twin menu screen.
95 struct pbt_scr *scr; // convinence pointer
96 struct pbt_menu *parent;
97 twin_window_t *window;
98 twin_pixmap_t *pixmap;
100 struct pbt_border border;
101 twin_argb32_t background_color;
102 struct pbt_menu_layout layout;
104 struct list* item_list;
105 unsigned int n_items;
106 uint32_t default_item_hash;
109 struct pbt_item *selected;
110 int (*on_open)(struct pbt_menu *menu);
113 struct pbt_menu *pbt_menu_create(void *talloc_ctx, const char *name,
114 struct pbt_scr *scr, struct pbt_menu *parent, const struct pbt_quad *q,
115 const struct pbt_menu_layout *layout);
116 void pbt_menu_set_focus(struct pbt_menu *menu, int focus);
117 void pbt_menu_set_selected(struct pbt_menu *menu, struct pbt_item *item);
118 struct pbt_quad *pbt_menu_get_item_quad(const struct pbt_menu *menu,
119 unsigned int pos, struct pbt_quad *q);
120 void pbt_menu_hide(struct pbt_menu *menu);
121 void pbt_menu_show(struct pbt_menu *menu, int hide);
123 static inline const char *pbt_menu_name(const struct pbt_menu *menu)
125 return menu->window->name;
128 static inline struct pbt_menu *pbt_menu_from_window(twin_window_t *window)
130 struct pbt_menu *menu = window->client_data;
136 static inline struct pbt_item *pbt_item_from_window(twin_window_t *window)
138 struct pbt_item *item = window->client_data;
144 static inline int pbt_item_is_selected(const struct pbt_item* item)
146 return item == item->menu->selected;
149 static inline void pbt_item_set_as_selected(struct pbt_item* item)
151 pbt_menu_set_selected(item->menu, item);
154 int pbt_item_editor(struct pbt_item *item);
156 static inline void pbt_item_redraw(struct pbt_item *item)
158 pbt_window_redraw(item->window);
161 static inline void pbt_menu_redraw(struct pbt_menu *menu)
163 pbt_window_redraw(menu->window);