summaryrefslogtreecommitdiff
path: root/frontends/framebuffer/fbtk/widget.h
blob: 5622723ee5e3c25c37e39b702f27045b5c48bde2 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf 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.
 *
 * NetSurf 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef NETSURF_FB_FBTK_WIDGET_H
#define NETSURF_FB_FBTK_WIDGET_H

#include <stdbool.h>

enum fbtk_widgettype_e {
	FB_WIDGET_TYPE_ROOT = 0,
	FB_WIDGET_TYPE_WINDOW,
	FB_WIDGET_TYPE_BITMAP,
	FB_WIDGET_TYPE_FILL,
	FB_WIDGET_TYPE_TEXT,
	FB_WIDGET_TYPE_HSCROLL,
	FB_WIDGET_TYPE_VSCROLL,
	FB_WIDGET_TYPE_USER,
};


/** Widget description.
 *
 * A widget is an entry in a tree structure which represents a
 * rectangular area with co-ordinates relative to its parent widget.
 * This area has a distinct set of callback operations for handling
 * events which occour within its boundries. A widget may have an
 * arbitrary number of child widgets. The order within the tree
 * determines a widgets z order.
 *
 *                                         ---
 *                                          A
 *                                          |
 *                                  +----------+
 *                             +--->| Button 3 |
 *                             |    +----------+
 *                             |       |    A
 *                             |       V    |
 *                             |    +----------+
 *                             |    | Button 2 |
 *                             |    +----------+
 *                             |       |    A
 *                             |       V    |
 *                             |    +----------+
 *                             |    | Button 1 |
 *                             |    +----------+
 *                             |       |    A
 *                             |       V    |
 *                      ---    |    +----------+
 *                       A     | +->|  Filled  |
 *                       |     | |  +----------+
 *                +----------+ | |     |
 *          +---->|          |-+ |     V
 *          |     | Window 1 |   |    ---  ---
 *          |     |          |---+          A
 *          |     +----------+              |
 *          |        |    A         +----------+               ---
 *          |        |    |    +--->| Button 2 |                A
 *          |        |    |    |    +----------+                |
 *          |        |    |    |       |    A         +-------------+
 *          |        |    |    |       |    |    +--->|  Button Up  |
 *          |        |    |    |       |    |    |    +-------------+
 *          |        |    |    |       |    |    |        |     A
 *          |        |    |    |       |    |    |        V     |
 *          |        |    |    |       |    |    |    +-------------+
 *          |        |    |    |       |    |    |    | Button Down |
 *          |        |    |    |       |    |    |    +-------------+
 *          |        |    |    |       |    |    |        |     A
 *          |        |    |    |       |    |    |        V     |
 *          |        |    |    |       |    |    |    +-------------+
 *          |        |    |    |       |    |    | +->|   Scroller  |
 *          |        |    |    |       V    |    | |  +-------------+
 *          |        |    |    |    +----------+ | |      |
 *          |        |    |    |    |          |-+ |      V
 *          |        |    |    |    | V Scroll |   |     ---
 *          |        |    |    |    |          |---+
 *          |        |    |    |    +----------+
 *          |        |    |    |       |    A
 *          |        |    |    |       V    |
 *          |        |    |    |    +----------+
 *          |        |    |    | +->| Button 1 |
 *          |        |    |    | |  +----------+
 *          |     +----------+ | |     |
 *          |     |          |-+ |     V
 *          |     | Window 2 |   |    ---
 *          |     |          |---+
 *          |     +----------+
 *          |        |    A
 *          |        V    |
 *          |    +------------+
 *     ---  |    | Background |
 *      A   | +->|   Bitmap   |
 *      |   | |  +------------+
 * +------+ | |      |
 * |      |-+ |      V
 * | Root |   |     ---
 * |      |---+
 * +------+
 *   |
 *   V
 *  ---
 *
 * Every widget is contained within this generic wrapper. The
 * integrated union provides for data specific to a widget type.
 */
struct fbtk_widget_s {
	struct fbtk_widget_s *next; /* next lower z ordered widget in tree */
	struct fbtk_widget_s *prev; /* next higher z ordered widget in tree */

	struct fbtk_widget_s *parent; /* parent widget */

	struct fbtk_widget_s *first_child; /* first child widget */
	struct fbtk_widget_s *last_child; /* last child widget */

	/* flags */
	bool mapped; /**< The widget is mapped/visible . */

	/* Generic properties */
	int x;
	int y;
	int width;
	int height;
	colour bg;
	colour fg;

	/* event callback handlers */
	fbtk_callback callback[FBTK_CBT_END];
	void *callback_context[FBTK_CBT_END];

	/* widget redraw */
	struct {
		bool child; /* A child of this widget requires redrawing */
		bool needed; /* the widget requires redrawing */
		int x;
		int y;
		int width;
		int height;
	} redraw;

	enum fbtk_widgettype_e type; /**< The type of the widget */


	union {
		/* toolkit base handle */
		struct {
			nsfb_t *fb;
			struct fbtk_widget_s *prev; /* previous widget pointer wasin */
			struct fbtk_widget_s *grabbed; /* widget that has grabbed pointer movement. */
			struct fbtk_widget_s *input;

			/* caret */
			struct {
				struct fbtk_widget_s *owner; /* widget / NULL */
				int x; /* relative to owner */
				int y; /* relative to owner */
				int height;
				void (*remove_cb)(fbtk_widget_t *widget);
			} caret;
		} root;

		/* bitmap */
		struct {
			struct fbtk_bitmap *bitmap;
		} bitmap;

		/* text */
		struct {
			char* text;
			bool outline;
			fbtk_enter_t enter;
			void *pw;
			int idx; /* caret pos in text */
			int len; /* text length */
			int width; /* text width in px */
			int idx_offset; /* caret pos in pixels */
		} text;

		/* application driven widget */
		struct {
			void *pw; /* private data for user widget */
		} user;

		struct {
			int minimum; /* lowest value of scrollbar */
			int maximum; /* highest value of scrollbar */
			int thumb; /* size of bar representing a page */
			int page; /* amount to page document */
			int position; /* position of bar */
			int drag; /* offset to start of drag */
			int drag_position; /* indicator bar pos at drag start */
			struct fbtk_widget_s *btnul; /* scroll button up/left */
			struct fbtk_widget_s *btndr; /* scroll button down/right*/
		} scroll;

	} u;
};


/* These functions are not considered part of the public API but are
 * not static as they are used by the higher level widget provision
 * routines
 */


/** creates a new widget and insert it into to hierachy.
 *
 * The widget is set to defaults of false, 0 or NULL.
 *
 * @param parent The parent widget. The new widget will be added with
 *               the shallowest z order relative to its siblings.
 * @param type The type of the widget.
 * @param x The x co-ordinate relative to the parent widget.
 * @param y The y co-ordinate relative to the parent widget.
 * @param width the widgets width. This will be clipped to the parent, if
 *          the value is 0 the largest extent which can fit within the parent
 *          is used, if the value is negative the largest value that will fit
 *          within the parent less the value given will be used.
 * @param height the widgets width. This will be clipped to the parent, if
 *          the value is 0 the largest extent which can fit within the parent
 *          is used, if the value is negative the largest value that will fit
 *          within the parent less the value given will be used.
 */
fbtk_widget_t *fbtk_widget_new(fbtk_widget_t *parent, enum fbtk_widgettype_e type, int x, int y, int width, int height);

/** find the root widget from any widget in the toolkit hierarchy.
 *
 * @param widget Any widget.
 * @return The root widget or NULL if \a widget was not valid.
 */
fbtk_widget_t *fbtk_get_root_widget(fbtk_widget_t *widget);

/** set pointer to bitmap in context.
 *
 * widget helper callback to set cursor image to the bitmap passed in
 * the callbacks private data.
 */
int fbtk_set_ptr(fbtk_widget_t *widget, fbtk_callback_info *cbi);

#endif

/*
 * Local Variables:
 * c-basic-offset:8
 * End:
 */