]> git.ozlabs.org Git - petitboot/blob - ui/twin/pbt-menu.h
discover/resource: create_url_resource should take ownership of url
[petitboot] / ui / twin / pbt-menu.h
1 /*
2  *  Copyright Geoff Levand <geoff@infradead.org>
3  *
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.
7  *
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.
12  *
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
16  */
17
18 #if !defined(_PBT_MENU_H)
19 #define _PBT_MENU_H
20
21 #include "list/list.h"
22 #include "types/types.h"
23
24 #include "pbt-scr.h"
25
26
27 /**
28  * struct pbt_item - A menu item.
29  */
30
31 struct pbt_item
32 {
33         struct list_item list;
34
35         struct pbt_menu *menu; // convinence pointer
36         struct pbt_client *pbt_client; // convinence pointer
37
38         twin_window_t *window;
39         twin_pixmap_t *pixmap_idle;
40         twin_pixmap_t *pixmap_selected;
41         twin_pixmap_t *pixmap_active;
42
43         struct pbt_menu *sub_menu;
44         struct pbt_item *selected_item;
45
46         int (*on_execute)(struct pbt_item *item);
47         int (*on_edit)(struct pbt_item *item);
48
49         union {
50                 struct device *pb_device;
51                 struct boot_option *pb_opt;
52         };
53         void *data;
54 };
55
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,
58         const char *text);
59
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)
62 {
63         return pbt_item_create(menu, name, position, icon_filename, NULL,
64                 NULL);
65 }
66
67 static inline const char *pbt_item_name(const struct pbt_item *item)
68 {
69         return item->window->name;
70 }
71
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,
74         int line);
75
76 struct pbt_text_layout {
77         twin_argb32_t color;
78         unsigned int font_size;
79 };
80
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;
89 };
90
91  /**
92   * struct pbt_menu - A twin menu screen.
93   */
94
95 struct pbt_menu {
96         struct pbt_scr *scr; // convinence pointer
97         struct pbt_menu *parent;
98         twin_window_t *window;
99         twin_pixmap_t *pixmap;
100
101         struct pbt_border border;
102         twin_argb32_t background_color;
103         struct pbt_menu_layout layout;
104
105         struct list* item_list;
106         unsigned int n_items;
107         uint32_t default_item_hash;
108
109         int has_focus;
110         struct pbt_item *selected;
111         int (*on_open)(struct pbt_menu *menu);
112 };
113
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);
123
124 static inline const char *pbt_menu_name(const struct pbt_menu *menu)
125 {
126         return menu->window->name;
127 }
128
129 static inline struct pbt_menu *pbt_menu_from_window(twin_window_t *window)
130 {
131         struct pbt_menu *menu = window->client_data;
132
133         assert(menu);
134         return menu;
135 }
136
137 static inline struct pbt_item *pbt_item_from_window(twin_window_t *window)
138 {
139         struct pbt_item *item = window->client_data;
140
141         assert(item);
142         return item;
143 }
144
145 static inline int pbt_item_is_selected(const struct pbt_item* item)
146 {
147         return item == item->menu->selected;
148 }
149
150 static inline void pbt_item_set_as_selected(struct pbt_item* item)
151 {
152         pbt_menu_set_selected(item->menu, item);
153 }
154
155 int pbt_item_editor(struct pbt_item *item);
156
157 static inline void pbt_item_redraw(struct pbt_item *item)
158 {
159         pbt_window_redraw(item->window);
160 }
161
162 static inline void pbt_menu_redraw(struct pbt_menu *menu)
163 {
164         pbt_window_redraw(menu->window);
165 }
166
167
168 #endif