summaryrefslogtreecommitdiffstats
path: root/ui/twin/pbt-menu.h
blob: 698b64d2852a0558d9f312820beb625eb8fb00ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *  Copyright Geoff Levand <geoff@infradead.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#if !defined(_PBT_MENU_H)
#define _PBT_MENU_H

#include "list/list.h"
#include "types/types.h"

#include "pbt-scr.h"


/**
 * struct pbt_item - A menu item.
 */

struct pbt_item
{
	struct list_item list;

	struct pbt_menu *menu; // convinence pointer
	struct pbt_client *pbt_client; // convinence pointer

	twin_window_t *window;
	twin_pixmap_t *pixmap_idle;
	twin_pixmap_t *pixmap_selected;
	twin_pixmap_t *pixmap_active;

	struct pbt_menu *sub_menu;
	struct pbt_item *selected_item;

	int (*on_execute)(struct pbt_item *item);
	int (*on_edit)(struct pbt_item *item);

	union {
		struct device *pb_device;
		struct boot_option *pb_opt;
	};
	void *data;
};

struct pbt_item *pbt_item_create(struct pbt_menu *menu, const char *name,
	unsigned int position, const char *icon_filename, const char *title,
	const char *text);

static inline struct pbt_item *pbt_item_create_reduced(struct pbt_menu *menu,
	const char *name, unsigned int position, const char *icon_filename)
{
	return pbt_item_create(menu, name, position, icon_filename, NULL,
		NULL);
}

static inline const char *pbt_item_name(const struct pbt_item *item)
{
	return item->window->name;
}

#define pbt_dump_item(_i) _pbt_dump_item(_i, __func__, __LINE__)
void _pbt_dump_item(const struct pbt_item* item, const char *func,
	int line);

struct pbt_text_layout {
	twin_argb32_t color;
	unsigned int font_size;
};

struct pbt_menu_layout {
	unsigned int item_height;
	unsigned int item_space;
	unsigned int text_space;
	//unsigned int icon_height;
	//unsigned int icon_width;
	struct pbt_text_layout title;
	struct pbt_text_layout text;
};

 /**
  * struct pbt_menu - A twin menu screen.
  */

struct pbt_menu {
	struct pbt_scr *scr; // convinence pointer
	struct pbt_menu *parent;
	twin_window_t *window;
	twin_pixmap_t *pixmap;

	struct pbt_border border;
	twin_argb32_t background_color;
	struct pbt_menu_layout layout;

	struct list* item_list;
	unsigned int n_items;
	uint32_t default_item_hash;

	int has_focus;
	struct pbt_item *selected;
	int (*on_open)(struct pbt_menu *menu);
};

struct pbt_menu *pbt_menu_create(void *talloc_ctx, const char *name,
	struct pbt_scr *scr, struct pbt_menu *parent, const struct pbt_quad *q,
	const struct pbt_menu_layout *layout);
void pbt_menu_set_focus(struct pbt_menu *menu, int focus);
void pbt_menu_set_selected(struct pbt_menu *menu, struct pbt_item *item);
struct pbt_quad *pbt_menu_get_item_quad(const struct pbt_menu *menu,
	unsigned int pos, struct pbt_quad *q);
void pbt_menu_hide(struct pbt_menu *menu);
void pbt_menu_show(struct pbt_menu *menu, int hide);

static inline const char *pbt_menu_name(const struct pbt_menu *menu)
{
	return menu->window->name;
}

static inline struct pbt_menu *pbt_menu_from_window(twin_window_t *window)
{
	struct pbt_menu *menu = window->client_data;

	assert(menu);
	return menu;
}

static inline struct pbt_item *pbt_item_from_window(twin_window_t *window)
{
	struct pbt_item *item = window->client_data;

	assert(item);
	return item;
}

static inline int pbt_item_is_selected(const struct pbt_item* item)
{
	return item == item->menu->selected;
}

static inline void pbt_item_set_as_selected(struct pbt_item* item)
{
	pbt_menu_set_selected(item->menu, item);
}

int pbt_item_editor(struct pbt_item *item);

static inline void pbt_item_redraw(struct pbt_item *item)
{
	pbt_window_redraw(item->window);
}

static inline void pbt_menu_redraw(struct pbt_menu *menu)
{
	pbt_window_redraw(menu->window);
}


#endif
OpenPOWER on IntegriCloud