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