NetSurf
widget.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef NETSURF_FB_FBTK_WIDGET_H
20#define NETSURF_FB_FBTK_WIDGET_H
21
22#include <stdbool.h>
23
33};
34
35
36/** Widget description.
37 *
38 * A widget is an entry in a tree structure which represents a
39 * rectangular area with co-ordinates relative to its parent widget.
40 * This area has a distinct set of callback operations for handling
41 * events which occour within its boundries. A widget may have an
42 * arbitrary number of child widgets. The order within the tree
43 * determines a widgets z order.
44 *
45 * ---
46 * A
47 * |
48 * +----------+
49 * +--->| Button 3 |
50 * | +----------+
51 * | | A
52 * | V |
53 * | +----------+
54 * | | Button 2 |
55 * | +----------+
56 * | | A
57 * | V |
58 * | +----------+
59 * | | Button 1 |
60 * | +----------+
61 * | | A
62 * | V |
63 * --- | +----------+
64 * A | +->| Filled |
65 * | | | +----------+
66 * +----------+ | | |
67 * +---->| |-+ | V
68 * | | Window 1 | | --- ---
69 * | | |---+ A
70 * | +----------+ |
71 * | | A +----------+ ---
72 * | | | +--->| Button 2 | A
73 * | | | | +----------+ |
74 * | | | | | A +-------------+
75 * | | | | | | +--->| Button Up |
76 * | | | | | | | +-------------+
77 * | | | | | | | | A
78 * | | | | | | | V |
79 * | | | | | | | +-------------+
80 * | | | | | | | | Button Down |
81 * | | | | | | | +-------------+
82 * | | | | | | | | A
83 * | | | | | | | V |
84 * | | | | | | | +-------------+
85 * | | | | | | | +->| Scroller |
86 * | | | | V | | | +-------------+
87 * | | | | +----------+ | | |
88 * | | | | | |-+ | V
89 * | | | | | V Scroll | | ---
90 * | | | | | |---+
91 * | | | | +----------+
92 * | | | | | A
93 * | | | | V |
94 * | | | | +----------+
95 * | | | | +->| Button 1 |
96 * | | | | | +----------+
97 * | +----------+ | | |
98 * | | |-+ | V
99 * | | Window 2 | | ---
100 * | | |---+
101 * | +----------+
102 * | | A
103 * | V |
104 * | +------------+
105 * --- | | Background |
106 * A | +->| Bitmap |
107 * | | | +------------+
108 * +------+ | | |
109 * | |-+ | V
110 * | Root | | ---
111 * | |---+
112 * +------+
113 * |
114 * V
115 * ---
116 *
117 * Every widget is contained within this generic wrapper. The
118 * integrated union provides for data specific to a widget type.
119 */
121 struct fbtk_widget_s *next; /* next lower z ordered widget in tree */
122 struct fbtk_widget_s *prev; /* next higher z ordered widget in tree */
123
124 struct fbtk_widget_s *parent; /* parent widget */
125
126 struct fbtk_widget_s *first_child; /* first child widget */
127 struct fbtk_widget_s *last_child; /* last child widget */
128
129 /* flags */
130 bool mapped; /**< The widget is mapped/visible . */
131
132 /* Generic properties */
133 int x;
134 int y;
135 int width;
139
140 /* event callback handlers */
143
144 /* widget redraw */
145 struct {
146 bool child; /* A child of this widget requires redrawing */
147 bool needed; /* the widget requires redrawing */
148 int x;
149 int y;
150 int width;
151 int height;
153
154 enum fbtk_widgettype_e type; /**< The type of the widget */
155
156
157 union {
158 /* toolkit base handle */
159 struct {
160 nsfb_t *fb;
161 struct fbtk_widget_s *prev; /* previous widget pointer wasin */
162 struct fbtk_widget_s *grabbed; /* widget that has grabbed pointer movement. */
164
165 /* caret */
166 struct {
167 struct fbtk_widget_s *owner; /* widget / NULL */
168 int x; /* relative to owner */
169 int y; /* relative to owner */
170 int height;
171 void (*remove_cb)(fbtk_widget_t *widget);
174
175 /* bitmap */
176 struct {
179
180 /* text */
181 struct {
182 char* text;
185 void *pw;
186 int idx; /* caret pos in text */
187 int len; /* text length */
188 int width; /* text width in px */
189 int idx_offset; /* caret pos in pixels */
191
192 /* application driven widget */
193 struct {
194 void *pw; /* private data for user widget */
196
197 struct {
198 int minimum; /* lowest value of scrollbar */
199 int maximum; /* highest value of scrollbar */
200 int thumb; /* size of bar representing a page */
201 int page; /* amount to page document */
202 int position; /* position of bar */
203 int drag; /* offset to start of drag */
204 int drag_position; /* indicator bar pos at drag start */
205 struct fbtk_widget_s *btnul; /* scroll button up/left */
206 struct fbtk_widget_s *btndr; /* scroll button down/right*/
208
209 } u;
210};
211
212
213/* These functions are not considered part of the public API but are
214 * not static as they are used by the higher level widget provision
215 * routines
216 */
217
218
219/** creates a new widget and insert it into to hierachy.
220 *
221 * The widget is set to defaults of false, 0 or NULL.
222 *
223 * @param parent The parent widget. The new widget will be added with
224 * the shallowest z order relative to its siblings.
225 * @param type The type of the widget.
226 * @param x The x co-ordinate relative to the parent widget.
227 * @param y The y co-ordinate relative to the parent widget.
228 * @param width the widgets width. This will be clipped to the parent, if
229 * the value is 0 the largest extent which can fit within the parent
230 * is used, if the value is negative the largest value that will fit
231 * within the parent less the value given will be used.
232 * @param height the widgets width. This will be clipped to the parent, if
233 * the value is 0 the largest extent which can fit within the parent
234 * is used, if the value is negative the largest value that will fit
235 * within the parent less the value given will be used.
236 */
238
239/** find the root widget from any widget in the toolkit hierarchy.
240 *
241 * @param widget Any widget.
242 * @return The root widget or NULL if \a widget was not valid.
243 */
245
246/** set pointer to bitmap in context.
247 *
248 * widget helper callback to set cursor image to the bitmap passed in
249 * the callbacks private data.
250 */
252
253#endif
254
255/*
256 * Local Variables:
257 * c-basic-offset:8
258 * End:
259 */
wimp_w parent
Definition: dialog.c:88
@ FBTK_CBT_END
Definition: fbtk.h:48
int(* fbtk_enter_t)(void *pw, char *text)
Definition: fbtk.h:86
int(* fbtk_callback)(fbtk_widget_t *widget, fbtk_callback_info *cbi)
Definition: fbtk.h:83
const char * type
Definition: filetype.cpp:44
int width
Definition: gui.c:160
int height
Definition: gui.c:161
framebuffer toolkit bitmaps
Definition: fbtk.h:63
widget callback information
Definition: fbtk.h:52
Widget description.
Definition: widget.h:120
enum fbtk_widgettype_e type
The type of the widget.
Definition: widget.h:154
bool mapped
The widget is mapped/visible .
Definition: widget.h:130
struct fbtk_widget_s * input
Definition: widget.h:163
void(* remove_cb)(fbtk_widget_t *widget)
Definition: widget.h:171
char * text
Definition: widget.h:182
struct fbtk_widget_s * last_child
Definition: widget.h:127
struct fbtk_widget_s::@35::@36::@41 caret
struct fbtk_widget_s * next
Definition: widget.h:121
bool outline
Definition: widget.h:183
struct fbtk_widget_s * btnul
Definition: widget.h:205
struct fbtk_widget_s * btndr
Definition: widget.h:206
int position
Definition: widget.h:202
struct fbtk_bitmap * bitmap
Definition: widget.h:177
struct fbtk_widget_s::@34 redraw
void * pw
Definition: widget.h:185
struct fbtk_widget_s * parent
Definition: widget.h:124
int maximum
Definition: widget.h:199
fbtk_enter_t enter
Definition: widget.h:184
struct fbtk_widget_s * first_child
Definition: widget.h:126
struct fbtk_widget_s * grabbed
Definition: widget.h:162
struct fbtk_widget_s::@35::@36 root
colour bg
Definition: widget.h:137
void * callback_context[FBTK_CBT_END]
Definition: widget.h:142
int drag_position
Definition: widget.h:204
int height
Definition: widget.h:136
struct fbtk_widget_s * prev
Definition: widget.h:122
int minimum
Definition: widget.h:198
struct fbtk_widget_s::@35::@39 user
bool child
Definition: widget.h:146
struct fbtk_widget_s::@35::@40 scroll
nsfb_t * fb
Definition: widget.h:160
fbtk_callback callback[FBTK_CBT_END]
Definition: widget.h:141
union fbtk_widget_s::@35 u
int idx_offset
Definition: widget.h:189
bool needed
Definition: widget.h:147
colour fg
Definition: widget.h:138
struct fbtk_widget_s * owner
Definition: widget.h:167
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
int fbtk_set_ptr(fbtk_widget_t *widget, fbtk_callback_info *cbi)
set pointer to bitmap in context.
Definition: fbtk.c:393
fbtk_widget_t * fbtk_widget_new(fbtk_widget_t *parent, enum fbtk_widgettype_e type, int x, int y, int width, int height)
creates a new widget and insert it into to hierachy.
Definition: fbtk.c:546
fbtk_widgettype_e
Definition: widget.h:24
@ FB_WIDGET_TYPE_TEXT
Definition: widget.h:29
@ FB_WIDGET_TYPE_FILL
Definition: widget.h:28
@ FB_WIDGET_TYPE_WINDOW
Definition: widget.h:26
@ FB_WIDGET_TYPE_BITMAP
Definition: widget.h:27
@ FB_WIDGET_TYPE_VSCROLL
Definition: widget.h:31
@ FB_WIDGET_TYPE_ROOT
Definition: widget.h:25
@ FB_WIDGET_TYPE_USER
Definition: widget.h:32
@ FB_WIDGET_TYPE_HSCROLL
Definition: widget.h:30
fbtk_widget_t * fbtk_get_root_widget(fbtk_widget_t *widget)
find the root widget from any widget in the toolkit hierarchy.
Definition: fbtk.c:412