1 #ifndef _XGLK_H
2 #define _XGLK_H
3 
4 #include "xglk_option.h"
5 #include <stdio.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 #include "glk.h"
9 #include "glkstart.h"
10 
11 #define LIBRARYNAME "XGlk"
12 #define LIBRARYVERSION "0.4.11"
13 
14 /* We define our own TRUE and FALSE and NULL, because ANSI
15     is a strange world. */
16 #ifndef TRUE
17 #define TRUE 1
18 #endif
19 #ifndef FALSE
20 #define FALSE 0
21 #endif
22 #ifndef NULL
23 #define NULL 0
24 #endif
25 
26 #define mouse_Reset (0)
27 #define mouse_Down (1)
28 #define mouse_Move (2)
29 #define mouse_Up (3)
30 
31 #define xmsg_mode_None (0)
32 #define xmsg_mode_Char (1)
33 #define xmsg_mode_Line (2)
34 
35 #define PackRGBColor(xcol)   \
36    ((((glui32)(xcol)->red << 8) & 0x00FF0000)   \
37   | (((glui32)(xcol)->green & 0x0000FF00))      \
38   | (((glui32)(xcol)->blue >> 8) & 0x000000FF))
39 
40 #define UnpackRGBColor(xcol, ui)  \
41   (((xcol)->blue = ((ui) & 0x000000FF) * 0x101),   \
42    ((xcol)->green = (((ui) >> 8) & 0x000000FF) * 0x101),   \
43    ((xcol)->red = (((ui) >> 16) & 0x000000FF) * 0x101))
44 
45 struct glk_window_struct;
46 typedef void (*cmdfunc_ptr)(struct glk_window_struct *win, int operand);
47 
48 typedef struct cmdentry_struct {
49   cmdfunc_ptr func;
50   int operand;
51   int ignoremods;
52   char *name;
53 } cmdentry_t;
54 
55 typedef struct fontnamespec_struct fontnamespec_t;
56 
57 typedef struct fontprefs_struct {
58   char *specname;
59   fontnamespec_t *spec;
60   int size, weight, oblique, proportional; /* all zero-based */
61   int justify; /* 0:left, 1:full, 2:center, 3:right */
62   int baseindent;
63   int parindent;
64   XColor forecolor;
65   XColor linkcolor;
66   XColor backcolor;
67 } fontprefs_t;
68 
69 typedef struct winprefs_struct {
70   int marginx, marginy;
71   int leading;
72   XColor forecolor;
73   XColor linkcolor;
74   XColor backcolor;
75   int sizehint, fixedhint, attribhint, justhint, indenthint, colorhint;
76   fontprefs_t style[style_NUMSTYLES];
77 } winprefs_t;
78 
79 typedef struct preferences_struct {
80   int win_x, win_y;
81   int win_w, win_h;
82   XColor forecolor;
83   XColor linkcolor;
84   XColor backcolor;
85   XColor techcolor, techucolor, techdcolor, selectcolor;
86   int ditherimages;
87   int underlinelinks, colorlinks;
88 
89   winprefs_t textbuffer;
90   winprefs_t textgrid;
91 
92   long buffersize;
93   long bufferslack;
94 
95   int historylength;
96   int prompt_defaults;
97 } preferences_t;
98 
99 typedef struct fontref_struct {
100   char *specname;
101   int justify;
102   int indent;
103   int parindent;
104   int ascent, descent;
105   int underliney;
106   int spacewidth;
107   XColor forecolor;
108   XColor linkcolor;
109   XColor backcolor;
110   XFontStruct *fontstr;
111 } fontref_t;
112 
113 typedef struct fontset_struct {
114   fontref_t gc[style_NUMSTYLES];
115   int lineheight;
116   int lineoff;
117   int baseindent;
118   XColor forecolor;
119   XColor linkcolor;
120   XColor backcolor;
121 } fontset_t;
122 
123 typedef struct wegscroll_struct {
124   void *rock;
125   cmdfunc_ptr scrollfunc;
126   cmdfunc_ptr scrolltofunc;
127 
128   XRectangle box;
129   int vistop, visbot;
130 
131   int drag_scrollmode; /* 0 for click in elevator; 1 for dragged in elevator;
132 			  2 for endzones; 3 for click in background */
133   int drag_hitypos;
134   long drag_origline;
135 } wegscroll_t;
136 
137 typedef struct picture_struct {
138   unsigned long id;
139   XImage *gimp;
140   long width, height; /* natural bounds */
141   Pixmap pix;
142   long pixwidth, pixheight; /* pixmap's bounds */
143   int refcount;
144   struct picture_struct *hash_next;
145 } picture_t;
146 
147 extern Display *xiodpy;
148 extern Colormap xiomap;
149 extern int xioscn;
150 extern int xiodepth;
151 extern int xiobackstore;
152 extern Window xiowin;
153 extern unsigned char *pixelcube;
154 extern int imageslegal;
155 extern GC gcfore, gcback, gctech, gctechu, gctechd, gcselect, gcflip;
156 extern GC gctextfore, gctextback;
157 extern Font textforefont;
158 extern unsigned long textforepixel, textbackpixel;
159 extern fontset_t plainfonts;
160 extern int xio_wid, xio_hgt;
161 extern XRectangle matte_box;
162 extern int xio_any_invalid;
163 extern int xmsg_msgmode;
164 extern preferences_t prefs;
165 
166 extern int xglk_init(int argc, char *argv[], glkunix_startup_t *startdata);
167 extern int xglk_open_connection(char *progname);
168 extern int xglk_init_preferences(int argc, char *argv[],
169   glkunix_startup_t *startdata);
170 extern void xglk_build_fontname(fontnamespec_t *spec, char *buf,
171   int size, int weight, int oblique, int proportional);
172 extern void xglk_event_loop(event_t *ev, glui32 millisec);
173 extern void xglk_event_poll(event_t *ev, glui32 millisec);
174 extern void xglk_arrange_window(void);
175 extern void xglk_invalidate(XRectangle *box);
176 extern void xglk_redraw(void);
177 extern void xglk_perform_click(int dir, XPoint *pt, int butnum,
178   unsigned int state);
179 extern void xglk_relax_memory(void);
180 extern void gli_draw_window_highlight(struct glk_window_struct *win,
181   int turnon);
182 extern void gli_draw_window_outline(XRectangle *winbox);
183 extern void gli_draw_window_margin(XColor *colref,
184   int outleft, int outtop, int outwidth, int outheight,
185   int inleft, int intop, int inwidth, int inheight);
186 extern void xglk_draw_dot(int xpos, int ypos, int linehgt);
187 extern void xglk_clearfor_string(XColor *colref, int xpos, int ypos,
188   int width, int height);
189 extern void xglk_draw_string(fontref_t *fontref, int islink,
190   int width, int xpos, int ypos, char *str, int len);
191 
192 extern void xglk_store_scrap(char *str, long len);
193 extern void xglk_clear_scrap(void);
194 extern void xglk_fetch_scrap(char **str, long *len);
195 extern void xglk_strip_garbage(char *str, long len);
196 
197 extern int init_xmsg(void);
198 extern void xmsg_redraw(void);
199 extern void xmsg_resize(int x, int y, int wid, int hgt);
200 extern void xmsg_set_message(char *str, int sticky);
201 extern void xmsg_check_timeout(void);
202 extern int xmsg_getline(char *prompt, char *buf, int maxlen, int *length);
203 extern int xmsg_getchar(char *prompt);
204 extern void xgc_msg_getchar(int op);
205 extern void xgc_msg_insert(int op);
206 extern void xgc_msg_delete(int op);
207 extern void xgc_msg_movecursor(int op);
208 extern void xgc_msg_enter(int op);
209 
210 extern void xweg_init_scrollbar(wegscroll_t *weg, void *rock,
211   cmdfunc_ptr scrollfunc, cmdfunc_ptr scrolltofunc);
212 extern void xweg_draw_scrollbar(wegscroll_t *weg);
213 extern void xweg_adjust_scrollbar(wegscroll_t *weg, int numlines,
214   int scrollline, int linesperpage);
215 extern void xweg_click_scrollbar(wegscroll_t *weg, int dir, XPoint *pt,
216   int butnum, int clicknum, unsigned int state,
217   int numlines, int scrollline, int linesperpage);
218 
219 extern int init_xkey(void);
220 extern void xkey_perform_key(int key, unsigned int state);
221 extern char *xkey_get_macro(int key);
222 extern void xkey_set_macro(int key, char *str, int chown);
223 extern void xkey_guess_focus(void);
224 
225 extern int xres_is_resource_map(void);
226 extern void xres_get_resource(glui32 usage, glui32 id,
227   FILE **file, long *pos, long *len, glui32 *type);
228 
229 extern int init_pictures(void);
230 extern int init_picture_colortab(XColor *cols, int numcols);
231 extern void picture_relax_memory(void);
232 extern picture_t *picture_find(unsigned long id);
233 extern void picture_release(picture_t *pic);
234 extern void picture_draw(picture_t *pic, Drawable dest, int xpos, int ypos,
235   int width, int height, XRectangle *clipbox);
236 
237 #define op_Cancel (0)
238 #define op_Meta (1)
239 #define op_ExplainKey (2)
240 #define op_DefineMacro (3)
241 #define op_ForeWin (4)
242 #define op_AllWindows (5)
243 #define op_Enter (6)
244 #define op_ForeChar (10)
245 #define op_BackChar (11)
246 #define op_ForeWord (12)
247 #define op_BackWord (13)
248 #define op_ForeLine (14)
249 #define op_BackLine (15)
250 #define op_BeginLine (16)
251 #define op_EndLine (17)
252 #define op_DownPage (20)
253 #define op_UpPage (21)
254 #define op_DownLine (22)
255 #define op_UpLine (23)
256 #define op_ToBottom (24)
257 #define op_ToTop (25)
258 #define op_Copy (30)
259 #define op_Wipe (31)
260 #define op_Yank (32)
261 #define op_Kill (33)
262 #define op_YankReplace (34)
263 #define op_Untype (35)
264 #define op_Erase (36)
265 
266 extern void xgc_focus(struct glk_window_struct *dummy, int op);
267 extern void xgc_redraw(struct glk_window_struct *win, int op);
268 extern void xgc_noop(struct glk_window_struct *dummy, int op);
269 extern void xgc_work_meta(struct glk_window_struct *dummy, int op);
270 extern void xgc_enter(struct glk_window_struct *win, int op);
271 extern void xgc_insert(struct glk_window_struct *win, int op);
272 extern void xgc_getchar(struct glk_window_struct *win, int op);
273 extern void xgc_movecursor(struct glk_window_struct *win, int op);
274 extern void xgc_scroll(struct glk_window_struct *win, int op);
275 extern void xgc_scrollto(struct glk_window_struct *win, int op);
276 extern void xgc_delete(struct glk_window_struct *win, int op);
277 extern void xgc_cutbuf(struct glk_window_struct *win, int op);
278 extern void xgc_history(struct glk_window_struct *win, int op);
279 
280 #endif /* _XGLK_H */
281