Mark shared variable declarations with extern
[hed.git] / src / ui / core.h
blob3358e193e9951ac9c6047b764d7a73f53bf0ed19
1 /* The user interface core */
2 /* $Id$ */
4 /*
5 * hed - Hexadecimal editor
6 * Copyright (C) 2004 Petr Baudis <pasky@ucw.cz>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef HED__UI_CORE_H
23 #define HED__UI_CORE_H
25 #include "util/lists.h"
28 /* Initialize the UI core. */
29 void ui_init(void);
31 /* Kill the UI core. */
32 void ui_done(void);
34 /* Possible prefix */
35 extern int xprefix; /* Letter prefix (e.g. 'g'). */
37 /* Final cursor position */
38 extern int cursor_x, cursor_y;
41 /* Components */
43 enum handler_result {
44 EVH_PASS,
45 EVH_HOLD,
46 EVH_SILENTHOLD, // EVH_HOLD, but don't redraw
47 EVH_XPREFIX,
48 EVH_CUSTOM_XPREFIX, // @xprefix is not cleared after the handler is done
51 /* Gets called to handle an event. */
52 struct ui_component;
53 struct ui_event;
54 typedef enum handler_result (*ui_comp_handler)(struct ui_component *, const struct ui_event *);
56 struct ui_component {
57 struct list_head list;
59 ui_comp_handler handler;
60 void *data;
63 /* Register UI component. */
64 struct ui_component *ui_register(ui_comp_handler handler, void *data);
66 /* Unregister and free UI component. */
67 void ui_unregister(struct ui_component *component);
70 /* Events */
72 struct ui_event {
73 enum ui_event_type {
74 EV_REDRAW,
75 EV_KEYBOARD,
76 EV_DONE,
77 } type;
78 union {
79 struct {
80 int ch;
81 } keyboard;
82 } v;
85 /* Poll for an event. Returns negative if nothing happenned.
86 * (That may occur e.g. when standard input reaches EOF.) */
87 int ui_pollevent(struct ui_event *event);
89 /* Propagate an event. (Just sending it to all components now. TODO:
90 * Hierarchy.) */
91 void ui_propevent(const struct ui_event *event);
93 /* Trigger a redraw event. */
94 static void ui_redraw(void);
98 /**** Inline functions and such. */
100 static inline void
101 ui_redraw(void)
103 static const struct ui_event rev = {
104 .type = EV_REDRAW,
106 ui_propevent(&rev);
109 #endif