OSDN Git Service

ifdef-ed official patches
[jnethack/source.git] / include / winX.h
1 /* NetHack 3.6  winX.h  $NHDT-Date: 1433806583 2015/06/08 23:36:23 $  $NHDT-Branch: master $:$NHDT-Revision: 1.15 $ */
2 /* Copyright (c) Dean Luick, 1992                                 */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 /*
6  * Definitions for the X11 window-port.  See doc/window.doc for details on
7  * the window interface.
8  */
9 #ifndef WINX_H
10 #define WINX_H
11
12 /*JP
13 **      for i18n by issei 1994/1/8
14 */
15 #ifdef XI18N
16 #include <X11/Xlocale.h>
17 #endif
18 #ifdef XAW_I18N
19 #include <X11/Xaw/Xawi18n.h>
20 #endif
21
22 #ifndef E
23 #define E extern
24 #endif
25
26 #if defined(BOS) || defined(NHSTDC)
27 #define DIMENSION_P int
28 #else
29 #ifdef WIDENED_PROTOTYPES
30 #define DIMENSION_P unsigned int
31 #else
32 #define DIMENSION_P Dimension
33 #endif
34 #endif
35
36 /*
37  * Generic text buffer.
38  */
39 #define START_SIZE 512 /* starting text buffer size */
40 struct text_buffer {
41     char *text;
42     int text_size;
43     int text_last;
44     int num_lines;
45 };
46
47 /*
48  * Information specific to a map window.
49  */
50 struct text_map_info_t {
51     unsigned char text[ROWNO][COLNO]; /* Actual displayed screen. */
52 #ifdef TEXTCOLOR
53     unsigned char colors[ROWNO][COLNO]; /* Color of each character. */
54     GC color_gcs[CLR_MAX],              /* GC for each color */
55         inv_color_gcs[CLR_MAX];         /* GC for each inverse color */
56 #define copy_gc color_gcs[NO_COLOR]
57 #define inv_copy_gc inv_color_gcs[NO_COLOR]
58 #else
59     GC copy_gc,      /* Drawing GC */
60         inv_copy_gc; /* Inverse drawing GC */
61 #endif
62
63     int square_width,  /* Saved font information so      */
64         square_height, /*   we can calculate the correct */
65         square_ascent, /*   placement of changes.         */
66         square_lbearing;
67 };
68
69 struct tile_glyph_info_t {
70     unsigned short glyph;
71     unsigned special;
72 };
73
74 struct tile_map_info_t {
75     struct tile_glyph_info_t glyphs[ROWNO][COLNO]; /* Saved glyph numbers. */
76     GC white_gc;
77     GC black_gc;
78     GC  clip_gc;
79     unsigned long image_width; /* dimensions of tile image */
80     unsigned long image_height;
81
82     int square_width,  /* Saved tile information so      */
83         square_height, /*   we can calculate the correct */
84         square_ascent, /*   placement of changes.         */
85         square_lbearing;
86 };
87
88 struct map_info_t {
89     Dimension viewport_width,     /* Saved viewport size, so we can */
90         viewport_height;          /*   clip to cursor on a resize.  */
91     unsigned char t_start[ROWNO], /* Starting column for new info. */
92         t_stop[ROWNO];            /* Ending column for new info. */
93
94     boolean is_tile; /* true if currently using tiles */
95     struct text_map_info_t text_map;
96     struct tile_map_info_t tile_map;
97 };
98
99 /*
100  * Information specific to a message window.
101  */
102 struct line_element {
103     struct line_element *next;
104     char *line;     /* char buffer */
105     int buf_length; /* length of buffer */
106     int str_length; /* length of string in buffer */
107 };
108
109 struct mesg_info_t {
110     XFontStruct *fs;                 /* Font for the window. */
111 /*JP*/
112 #ifdef XI18N
113     XFontSet    fontset;
114 #endif
115     int num_lines;                   /* line count */
116     struct line_element *head;       /* head of circular line queue */
117     struct line_element *line_here;  /* current drawn line position */
118     struct line_element *last_pause; /* point to the line after the prev */
119     /*     bottom of screen                     */
120     struct line_element *last_pause_head; /* pointer to head of previous */
121     /* turn                                     */
122     GC gc;           /* GC for text drawing */
123     int char_width,  /* Saved font information so we can  */
124         char_height, /*   calculate the correct placement */
125         char_ascent, /*   of changes.                */
126         char_lbearing;
127     Dimension viewport_width, /* Saved viewport size, so we can adjust */
128         viewport_height;      /*   the slider on a resize.               */
129     Boolean dirty;            /* Lines have been added to the window. */
130 };
131
132 /*
133  * Information specific to a "text" status window.
134  */
135 struct status_info_t {
136     struct text_buffer text; /* Just a text buffer. */
137 };
138
139 /*
140  * Information specific to a menu window.  First a structure for each
141  * menu entry, then the structure for each menu window.
142  */
143 typedef struct x11_mi {
144     struct x11_mi *next;
145     anything identifier; /* Opaque type to identify this selection */
146     long pick_count;     /* specific selection count; -1 if none */
147     char *str;           /* The text of the item. */
148     int attr;            /* Attribute for the line. */
149     boolean selected;    /* Been selected? */
150     char selector;       /* Char used to select this entry. */
151     char gselector;      /* Group selector. */
152 } x11_menu_item;
153
154 struct menu {
155     x11_menu_item *base;  /* Starting pointer for item list. */
156     x11_menu_item *last;  /* End pointer for item list. */
157     const char *query;    /* Query string. */
158     const char *gacc;     /* Group accelerators. */
159     int count;            /* Number of strings. */
160     String *list_pointer; /* String list. */
161     Boolean *sensitive;   /* Active list. */
162     char curr_selector;   /* Next keyboard accelerator to assign, */
163     /*   if 0, then we're out.          */
164 };
165
166 struct menu_info_t {
167     struct menu curr_menu; /* Menu being displayed. */
168     struct menu new_menu;  /* New menu being built. */
169
170     XFontStruct *fs;           /* Font for the window. */
171 /*JP*/
172 #ifdef XI18N
173     XFontSet    fontset;
174 #endif
175     long menu_count;           /* number entered by user */
176     Dimension line_height;     /* Total height of a line of text. */
177     Dimension internal_height; /* Internal height between widget & border */
178     Dimension internal_width;  /* Internal width between widget & border */
179     short how;                 /* Menu mode PICK_NONE, PICK_ONE, PICK_ANY */
180     boolean valid_widgets;     /* TRUE if widgets have been created. */
181     boolean is_menu;   /* Has been confirmed to being a menu window. */
182     boolean is_active; /* TRUE when waiting for user input. */
183     boolean is_up;     /* TRUE when window is popped-up. */
184     boolean cancelled; /* Menu has been explicitly cancelled. */
185     boolean counting;  /* true when menu_count has a valid value */
186 };
187
188 /*
189  * Information specific to a text window.
190  */
191 struct text_info_t {
192     struct text_buffer text;
193     XFontStruct *fs;        /* Font for the text window. */
194 /*JP*/
195 #ifdef XI18N
196     XFontSet    fontset;
197 #endif
198     int max_width;          /* Width of widest line so far. */
199     int extra_width,        /* Sum of left and right border widths. */
200         extra_height;       /* Sum of top and bottom border widths. */
201     boolean blocked;        /*  */
202     boolean destroy_on_ack; /* Destroy this window when acknowledged. */
203 #ifdef GRAPHIC_TOMBSTONE
204     boolean is_rip; /* This window needs a tombstone. */
205 #endif
206 };
207
208 /*
209  * Basic window structure.
210  */
211 struct xwindow {
212     int type;              /* type of nethack window */
213     Widget popup;          /* direct parent of widget w or viewport */
214     Widget w;              /* the widget that does things */
215     Dimension pixel_width; /* window size, in pixels */
216     Dimension pixel_height;
217     int prevx, cursx; /* Cursor position, only used by    */
218     int prevy, cursy; /*   map and "plain" status windows.*/
219
220     union {
221         struct map_info_t *Map_info;       /* map window info */
222         struct mesg_info_t *Mesg_info;     /* message window info */
223         struct status_info_t *Status_info; /* status window info */
224         struct menu_info_t *Menu_info;     /* menu window info */
225         struct text_info_t *Text_info;     /* menu window info */
226     } Win_info;
227     boolean keep_window;
228 };
229
230 /* Defines to use for the window information union. */
231 #define map_information Win_info.Map_info
232 #define mesg_information Win_info.Mesg_info
233 #define status_information Win_info.Status_info
234 #define menu_information Win_info.Menu_info
235 #define text_information Win_info.Text_info
236
237 #define MAX_WINDOWS 20 /* max number of open windows */
238
239 #define NHW_NONE 0 /* Unallocated window type.  Must be */
240 /* different from any other NHW_* type. */
241
242 #define NO_CLICK 0 /* No click occurred on the map window. Must */
243 /* be different than CLICK_1 and CLICK_2.   */
244
245 #define DEFAULT_MESSAGE_WIDTH 60 /* width in chars of the message window */
246
247 #define DISPLAY_FILE_SIZE 35 /* Max number of lines in the default      */
248 /* file display window.                 */
249
250 #define MAX_KEY_STRING 64 /* String size for converting a keypress */
251 /* event into a character(s)             */
252
253 #define DEFAULT_LINES_DISPLAYED 12 /* # of lines displayed message window */
254 #define MAX_HISTORY 60             /* max history saved on message window */
255
256 /* Window variables (winX.c). */
257 E struct xwindow window_list[MAX_WINDOWS];
258 E XtAppContext app_context; /* context of application */
259 E Widget toplevel;          /* toplevel widget */
260 E Atom wm_delete_window;    /* delete window protocol */
261 E boolean exit_x_event;     /* exit condition for event loop */
262 #define EXIT_ON_KEY_PRESS 0 /* valid values for exit_x_event */
263 #define EXIT_ON_KEY_OR_BUTTON_PRESS 1
264 #define EXIT_ON_EXIT 2
265 #define EXIT_ON_SENT_EVENT 3
266 E int click_x, click_y, click_button, updated_inventory;
267
268 typedef struct {
269     Boolean slow;
270     Boolean autofocus;
271     Boolean message_line;
272     Boolean double_tile_size; /* double tile size */
273     String tile_file;         /* name of file to open for tiles */
274 #ifdef X11LARGETILE
275     int     tile_width;
276     int     tile_height;
277 #endif
278     String icon;              /* name of desired icon */
279     int message_lines;        /* number of lines to attempt to show */
280     String pet_mark_bitmap;   /* X11 bitmap file used to mark pets */
281     Pixel pet_mark_color;     /* color of pet mark */
282     String pilemark_bitmap;   /* X11 bitmap file used to mark item piles */
283     Pixel pilemark_color;     /* color of item pile mark */
284 #ifdef GRAPHIC_TOMBSTONE
285     String tombstone; /* name of XPM file for tombstone */
286     int tombtext_x;   /* x-coord of center of first tombstone text */
287     int tombtext_y;   /* y-coord of center of first tombstone text */
288     int tombtext_dx;  /* x-displacement between tombstone line */
289     int tombtext_dy;  /* y-displacement between tombstone line */
290 #endif
291 } AppResources;
292
293 E AppResources appResources;
294 E void (*input_func)();
295
296 extern struct window_procs X11_procs;
297
298 /* Check for an invalid window id. */
299 #define check_winid(window)                                             \
300     if ((window) < 0 || (window) >= MAX_WINDOWS) {                      \
301         panic("illegal windid [%d] in %s at line %d", window, __FILE__, \
302               __LINE__);                                                \
303     }
304
305 /* ### dialogs.c ### */
306 E Widget
307 FDECL(CreateDialog, (Widget, String, XtCallbackProc, XtCallbackProc));
308 E void FDECL(SetDialogPrompt, (Widget, String));
309 E String FDECL(GetDialogResponse, (Widget));
310 E void FDECL(SetDialogResponse, (Widget, String));
311 E void FDECL(positionpopup, (Widget, BOOLEAN_P));
312
313 /* ### winX.c ### */
314 E struct xwindow *FDECL(find_widget, (Widget));
315 E Boolean FDECL(nhApproxColor, (Screen *, Colormap, char *, XColor *));
316 E Dimension FDECL(nhFontHeight, (Widget));
317 E char FDECL(key_event_to_char, (XKeyEvent *));
318 E void FDECL(msgkey, (Widget, XtPointer, XEvent *));
319 E void FDECL(nh_XtPopup, (Widget, int, Widget));
320 E void FDECL(nh_XtPopdown, (Widget));
321 E void FDECL(win_X11_init, (int));
322 E void FDECL(nh_keyscroll, (Widget, XEvent *, String *, Cardinal *));
323
324 /* ### winmesg.c ### */
325 E void FDECL(set_message_slider, (struct xwindow *));
326 E void FDECL(create_message_window, (struct xwindow *, BOOLEAN_P, Widget));
327 E void FDECL(destroy_message_window, (struct xwindow *));
328 E void FDECL(display_message_window, (struct xwindow *));
329 E void FDECL(append_message, (struct xwindow *, const char *));
330 E void FDECL(set_last_pause, (struct xwindow *));
331
332 /* ### winmap.c ### */
333 E void NDECL(post_process_tiles);
334 E void FDECL(check_cursor_visibility, (struct xwindow *));
335 E void FDECL(display_map_window, (struct xwindow *));
336 E void FDECL(clear_map_window, (struct xwindow *));
337 E void FDECL(map_input, (Widget, XEvent *, String *, Cardinal *));
338 E void FDECL(set_map_size, (struct xwindow *, DIMENSION_P, DIMENSION_P));
339 E void FDECL(create_map_window, (struct xwindow *, BOOLEAN_P, Widget));
340 E void FDECL(destroy_map_window, (struct xwindow *));
341 E int FDECL(x_event, (int));
342
343 /* ### winmenu.c ### */
344 E void FDECL(menu_delete, (Widget, XEvent *, String *, Cardinal *));
345 E void FDECL(menu_key, (Widget, XEvent *, String *, Cardinal *));
346 E void FDECL(create_menu_window, (struct xwindow *));
347 E void FDECL(destroy_menu_window, (struct xwindow *));
348
349 /* ### winmisc.c ### */
350 E void FDECL(ps_key, (Widget, XEvent *, String *,
351                       Cardinal *)); /* player selection action */
352 E void FDECL(race_key, (Widget, XEvent *, String *,
353                         Cardinal *)); /* race selection action */
354 E void FDECL(gend_key, (Widget, XEvent *, String *, Cardinal *)); /* gender */
355 E void FDECL(algn_key,
356              (Widget, XEvent *, String *, Cardinal *)); /* alignment */
357 E void FDECL(ec_delete, (Widget, XEvent *, String *, Cardinal *));
358 E void FDECL(ec_key, (Widget, XEvent *, String *,
359                       Cardinal *)); /* extended command action */
360
361 /* ### winstatus.c ### */
362 E void FDECL(create_status_window, (struct xwindow *, BOOLEAN_P, Widget));
363 E void FDECL(destroy_status_window, (struct xwindow *));
364 E void FDECL(adjust_status, (struct xwindow *, const char *));
365 E void NDECL(null_out_status);
366 E void NDECL(check_turn_events);
367
368 /* ### wintext.c ### */
369 E void FDECL(delete_text, (Widget, XEvent *, String *, Cardinal *));
370 E void FDECL(dismiss_text, (Widget, XEvent *, String *, Cardinal *));
371 E void FDECL(key_dismiss_text, (Widget, XEvent *, String *, Cardinal *));
372 #ifdef GRAPHIC_TOMBSTONE
373 E void FDECL(rip_dismiss_text, (Widget, XEvent *, String *, Cardinal *));
374 #endif
375 E void FDECL(add_to_text_window, (struct xwindow *, int, const char *));
376 E void FDECL(display_text_window, (struct xwindow *, BOOLEAN_P));
377 E void FDECL(create_text_window, (struct xwindow *));
378 E void FDECL(destroy_text_window, (struct xwindow *));
379 E void FDECL(clear_text_window, (struct xwindow *));
380 E void FDECL(append_text_buffer, (struct text_buffer *, const char *,
381                                   BOOLEAN_P)); /* text buffer routines */
382 E void FDECL(init_text_buffer, (struct text_buffer *));
383 E void FDECL(clear_text_buffer, (struct text_buffer *));
384 E void FDECL(free_text_buffer, (struct text_buffer *));
385 #ifdef GRAPHIC_TOMBSTONE
386 E void FDECL(calculate_rip_text, (int, time_t));
387 #endif
388
389 /* ### winval.c ### */
390 E Widget FDECL(create_value, (Widget, const char *));
391 E void FDECL(set_name, (Widget, const char *));
392 E void FDECL(set_name_width, (Widget, int));
393 E int FDECL(get_name_width, (Widget));
394 E void FDECL(set_value, (Widget, const char *));
395 E void FDECL(set_value_width, (Widget, int));
396 E int FDECL(get_value_width, (Widget));
397 E void FDECL(hilight_value, (Widget));
398 E void FDECL(swap_fg_bg, (Widget));
399
400 /* external declarations */
401 E void FDECL(X11_init_nhwindows, (int *, char **));
402 E void NDECL(X11_player_selection);
403 E void NDECL(X11_askname);
404 E void NDECL(X11_get_nh_event);
405 E void FDECL(X11_exit_nhwindows, (const char *));
406 E void FDECL(X11_suspend_nhwindows, (const char *));
407 E void NDECL(X11_resume_nhwindows);
408 E winid FDECL(X11_create_nhwindow, (int));
409 E void FDECL(X11_clear_nhwindow, (winid));
410 E void FDECL(X11_display_nhwindow, (winid, BOOLEAN_P));
411 E void FDECL(X11_destroy_nhwindow, (winid));
412 E void FDECL(X11_curs, (winid, int, int));
413 E void FDECL(X11_putstr, (winid, int, const char *));
414 E void FDECL(X11_display_file, (const char *, BOOLEAN_P));
415 E void FDECL(X11_start_menu, (winid));
416 E void FDECL(X11_add_menu, (winid, int, const ANY_P *, CHAR_P, CHAR_P, int,
417                             const char *, BOOLEAN_P));
418 E void FDECL(X11_end_menu, (winid, const char *));
419 E int FDECL(X11_select_menu, (winid, int, MENU_ITEM_P **));
420 E void NDECL(X11_update_inventory);
421 E void NDECL(X11_mark_synch);
422 E void NDECL(X11_wait_synch);
423 #ifdef CLIPPING
424 E void FDECL(X11_cliparound, (int, int));
425 #endif
426 E void FDECL(X11_print_glyph, (winid, XCHAR_P, XCHAR_P, int, int));
427 E void FDECL(X11_raw_print, (const char *));
428 E void FDECL(X11_raw_print_bold, (const char *));
429 E int NDECL(X11_nhgetch);
430 E int FDECL(X11_nh_poskey, (int *, int *, int *));
431 E void NDECL(X11_nhbell);
432 E int NDECL(X11_doprev_message);
433 E char FDECL(X11_yn_function, (const char *, const char *, CHAR_P));
434 E void FDECL(X11_getlin, (const char *, char *));
435 E int NDECL(X11_get_ext_cmd);
436 E void FDECL(X11_number_pad, (int));
437 E void NDECL(X11_delay_output);
438
439 /* other defs that really should go away (they're tty specific) */
440 E void NDECL(X11_start_screen);
441 E void NDECL(X11_end_screen);
442
443 #ifdef GRAPHIC_TOMBSTONE
444 E void FDECL(X11_outrip, (winid, int, time_t));
445 #else
446 E void FDECL(genl_outrip, (winid, int, time_t));
447 #endif
448
449 E void FDECL(X11_preference_update, (const char *));
450
451 #endif /* WINX_H */