Created common signature for panel event handling functions.
[xuni.git] / src / widget / widgets.h
blob5ba44984096bd4b4ab208676351ab9441c74bee5
1 /*! \file widgets.h
3 */
5 #ifndef XUNI_GUARD_WIDGETS_H
6 #define XUNI_GUARD_WIDGETS_H
8 /*! The type of a widget.
10 The order of these enumerated values should not matter.
12 enum widget_type_t {
13 WIDGET_NONE = -1,
14 WIDGET_BOX,
15 WIDGET_BUTTON,
16 WIDGET_CHECKBOX,
17 WIDGET_COMBOBOX,
18 WIDGET_FONT,
19 WIDGET_IMAGE,
20 WIDGET_IMAGE_TILE,
21 WIDGET_LABEL,
22 WIDGET_LISTBOX,
23 WIDGET_PANEL,
24 WIDGET_SCROLLBAR,
25 WIDGET_TEXTAREA,
26 WIDGET_TEXTBOX,
27 WIDGET_THEME,
28 WIDGET_LAST
30 #if !1
31 /* ideas */
32 WIDGET_PULLDOWN,
33 WIDGET_MENU,
34 WIDGET_TAB,
35 WIDGET_GROUP,
36 WIDGET_RADIOBUTTON
37 #endif
40 enum widget_visibility_t {
41 /*! If unset, the widget cannot be selected -- that is, when sel members
42 are being set, this widget is simply passed over. Parents and children
43 of this widget are unaffected by this flag.
45 WIDGET_VISIBILITY_SELABLE = 1 << 0,
47 /*! If unset, when the widget is selected, its parent widget is considered
48 for selection. That is, the parent could have its sel member set as
49 well. This original widget still gets assigned to the sel->p.widget
50 pointer, however.
52 WIDGET_VISIBILITY_INDEPENDENT = 1 << 1,
54 /*! If unset, when the widget is selected, all of its children are
55 considered for selection (rather than just the last widget painted).
57 This is the inverse of WIDGET_VISIBILITY_INDEPENDENT.
59 WIDGET_VISIBILITY_NOT_COMPOSE = 1 << 2,
61 /*! If unset, the widget is always in "normal" mode; the widget does
62 not respond to hovering or clicking.
64 WIDGET_VISIBILITY_CLICKABLE = 1 << 3,
66 /*! If unset, the widget is completely invisible. */
67 WIDGET_VISIBILITY_VISIBLE = 1 << 4,
69 /*! All visibility types enabled (default). */
70 WIDGET_VISIBILITY_ALL = (1 << 5) - 1
73 typedef size_t widget_id_type_t;
75 /*! A nameid, a way to efficiently refer to a widget.
77 When widgets are created from resource files, their names are in strings.
78 However, referencing widgets by strings is inefficient. By "binding" a
79 number to each widget that needs referencing, much more efficient
80 referencing can be achieved.
82 These numbers are called "wids", short for "widget identifiers". They are
83 also frequently referred to as "nameids", or even just "ids".
85 These wids which are bound to widgets are specific to each panel. That is,
86 each panel can have its own wid 0, for example. wids are usually specified
87 as enums so that they increment automatically. However, wids need not be
88 contiguous. (Though if they are not, memory would be wasted.)
90 widget_nameid_access(), or, for multiple nested nameids,
91 widget_nameid_follow(), can be used to access these numerical widget ids.
93 struct widget_nameid_t {
94 widget_id_type_t id; /* mostly redundant */
95 const char *name; /* mostly redundant */
96 struct widget_t *widget;
99 /*! An array of struct widget_nameid_ts. Used by panels via
100 struct panel_data_t.
102 struct nameid_t {
103 struct widget_nameid_t *widget;
104 size_t widgets;
107 struct xuni_accelerator_key_t {
108 SDL_keysym key;
109 struct widget_t *widget;
112 struct xuni_accelerator_t {
113 struct xuni_accelerator_key_t *key;
114 size_t n;
117 enum widget_event_t {
118 WIDGET_EVENT_FREE,
119 WIDGET_EVENT_UPDATE_TEXT,
120 WIDGET_EVENT_PAINT,
121 WIDGET_EVENT_REPOSITION,
122 WIDGET_EVENT_RESCALE,
123 /*WIDGET_EVENT_ACTIVATE,
124 WIDGET_EVENT_REVERT,
125 WIDGET_EVENT_DEACTIVATE,*/
126 WIDGET_EVENTS
129 typedef void (*widget_event_handler_t)(struct xuni_t *xuni,
130 struct widget_t *widget, enum widget_event_t event);
132 typedef void (*widget_event_func_t)(struct xuni_t *xuni,
133 struct widget_t *widget);
135 struct wtype_t {
136 const char *name;
137 /*size_t type;*/
138 widget_event_handler_t handler;
141 struct wtype_array_t {
142 struct wtype_t *type;
143 size_t types;
146 /* !!! needs alphabetical ordering */
147 enum panel_event_type_t {
148 PANEL_EVENT_NONE = -1,
149 PANEL_EVENT_FREE,
150 PANEL_EVENT_EVENT,
151 PANEL_EVENT_INIT,
152 PANEL_EVENT_PAINT,
153 PANEL_EVENT_START,
154 PANEL_EVENT_CLICK,
155 PANEL_EVENT_DEACTIVATE,
156 PANEL_EVENT_SEL,
157 PANEL_EVENTS
160 struct panel_event_init_t {
161 struct widget_t *panel;
162 struct resource_t *settings;
165 struct panel_event_start_t {
166 int unused;
169 struct panel_event_event_t {
170 panel_type_t *mode;
171 SDL_Event *event;
172 struct widget_t *widget;
175 struct panel_event_sel_t {
176 panel_type_t mode;
177 int xp, yp;
178 int click;
181 struct panel_event_click_t {
182 struct widget_t *widget;
183 panel_type_t *mode;
186 struct panel_event_deactivate_t {
187 struct widget_t *widget;
190 struct panel_event_paint_t {
191 panel_type_t mode;
194 struct panel_event_free_t {
195 int unused;
198 struct panel_data_t;
200 typedef int (*panel_event_func_t)(struct xuni_t *xuni,
201 struct panel_data_t *data);
203 struct panel_event_t {
204 enum panel_event_type_t type;
206 union {
207 struct panel_event_init_t init;
208 struct panel_event_start_t start;
209 struct panel_event_event_t event;
210 struct panel_event_sel_t sel;
211 struct panel_event_click_t click;
212 struct panel_event_deactivate_t deactivate;
213 struct panel_event_paint_t paint;
214 struct panel_event_free_t free;
215 } p;
217 panel_event_func_t handler;
220 #if 0
221 typedef void (*init_func_t)(void *vdata, struct xuni_t *xuni,
222 struct widget_t *panel, struct resource_t *settings);
223 typedef void (*start_func_t)(void *vdata, struct xuni_t *xuni);
224 typedef int (*event_func_t)(void *vdata, struct xuni_t *xuni,
225 panel_type_t *mode, SDL_Event *event);
226 typedef int (*set_widget_sel_func_t)(struct xuni_t *xuni, panel_type_t mode,
227 int xp, int yp, int click, void *vdata);
228 typedef int (*perform_click_func_t)(struct widget_t *widget,
229 panel_type_t *mode, void *vdata, struct xuni_t *xuni);
230 typedef void (*deactivate_func_t)(void *vdata, struct xuni_t *xuni,
231 struct widget_t *widget);
232 typedef void (*paint_func_t)(void *vdata, panel_type_t mode,
233 struct xuni_t *xuni);
234 typedef void (*free_func_t)(void *vdata, struct xuni_t *xuni);
235 #endif
237 struct panel_data_t {
238 void *data;
239 int frameupdate;
241 struct panel_event_t event[PANEL_EVENTS];
243 struct nameid_t *nameid;
245 struct xuni_accelerator_t *accel;
248 /*! Generic GUI widget structure. */
249 struct widget_t {
250 char *name;
251 widget_id_type_t id;
253 struct widget_t *base;
254 size_t type;
256 union {
257 struct box_t *box;
258 struct button_t *button;
259 struct checkbox_t *checkbox;
260 struct combobox_t *combobox;
261 struct font_t *font;
262 struct image_t *image;
263 struct image_tile_t *image_tile;
264 struct label_t *label;
265 struct listbox_t *listbox;
266 struct panel_data_t *panel;
267 struct scrollbar_t *scrollbar;
268 struct textarea_t *textarea;
269 struct textbox_t *textbox;
270 struct theme_data_t *theme;
271 } p;
273 struct panel_t *compose;
274 struct pos_t *pos;
276 enum widget_visibility_t visibility;
278 struct widget_t *selwidget;
280 int sel;
281 int repaint; /* !!! ... */
284 void delete_widget(struct xuni_t *xuni, struct panel_t *panel, size_t n);
285 void delete_widget_pointer(struct xuni_t *xuni, struct widget_t *widget);
286 void add_widget(struct panel_t *panel, struct widget_t *widget);
287 void add_allocate_widget(struct widget_t *base, char *name);
288 void add_allocate_widget_compose(struct widget_t *base, char *name);
289 struct panel_t *allocate_panel(struct widget_t *base);
290 struct widget_t *allocate_widget(char *name, struct widget_t *base);
291 void init_widget_pos(struct widget_t *widget, double x, double y,
292 double w, double h, enum pos_pack_t pack);
293 void clear_widget_clip(struct xuni_t *xuni, struct widget_t *widget);
294 void add_panel_clip(struct xuni_t *xuni, struct widget_t *widget,
295 int xoff, int yoff, int xclip, int yclip, int wclip, int hclip);
296 void add_widget_clip_nonrec(struct xuni_t *xuni, struct widget_t *widget,
297 int xoff, int yoff, int xclip, int yclip, int wclip, int hclip);
298 void add_widget_clip(struct xuni_t *xuni, struct widget_t *widget,
299 int xoff, int yoff, int xclip, int yclip, int wclip, int hclip);
300 void add_widget_accelerator(struct xuni_t *xuni, struct widget_t *panel,
301 struct widget_t *widget, SDLKey key, SDLMod mod);
302 struct widget_t *last_compose_widget(struct widget_t *widget);
303 struct widget_t *widget_nameid_access(struct widget_t *widget, size_t n);
304 struct widget_t *widget_nameid_follow(struct widget_t *widget, ...);
305 int widget_is_parent(struct widget_t *search, struct widget_t *widget);
306 int widget_name_match(const char *string, const char *buffer, size_t len);
307 struct widget_t *find_widget(struct widget_t *widget, const char *name);
308 void widget_event(struct xuni_t *xuni, struct widget_t *widget,
309 enum widget_event_t event);
310 void widget_compose_event(struct xuni_t *xuni, struct widget_t *widget,
311 enum widget_event_t event);
312 int get_real_pos(double scale, int basereal);
314 void init_wtype(struct xuni_t *xuni, struct wtype_array_t *wtype);
315 void free_wtype(struct wtype_array_t *wtype);
316 void register_widget_type(struct xuni_t *xuni, const char *name, size_t type,
317 widget_event_handler_t handler);
318 void call_widget_event(struct xuni_t *xuni, struct widget_t *widget,
319 enum widget_event_t type);
320 void call_widget_event_func(struct xuni_t *xuni, struct widget_t *widget,
321 enum widget_event_t event, widget_event_func_t function[],
322 size_t functions);
324 int assert_widget_type(struct xuni_t *xuni, struct widget_t *widget,
325 size_t type, const char *file, int line);
327 /* only because of init_wtype() */
328 #include "box.h"
329 #include "button.h"
330 #include "checkbox.h"
331 #include "combobox.h"
332 #include "font.h"
333 #include "image.h"
334 #include "image_tile.h"
335 #include "label.h"
336 #include "listbox.h"
337 #include "panel.h"
338 #include "scrollbar.h"
339 #include "textarea.h"
340 #include "textbox.h"
341 #include "theme.h"
343 #endif