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.
13 ** for i18n by issei 1994/1/8
16 #include <X11/Xlocale.h>
19 #include <X11/Xaw/Xawi18n.h>
26 #if defined(BOS) || defined(NHSTDC)
27 #define DIMENSION_P int
29 #ifdef WIDENED_PROTOTYPES
30 #define DIMENSION_P unsigned int
32 #define DIMENSION_P Dimension
37 * Generic text buffer.
39 #define START_SIZE 512 /* starting text buffer size */
48 * Information specific to a map window.
50 struct text_map_info_t {
51 unsigned char text[ROWNO][COLNO]; /* Actual displayed screen. */
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]
59 GC copy_gc, /* Drawing GC */
60 inv_copy_gc; /* Inverse drawing GC */
63 int square_width, /* Saved font information so */
64 square_height, /* we can calculate the correct */
65 square_ascent, /* placement of changes. */
69 struct tile_glyph_info_t {
74 struct tile_map_info_t {
75 struct tile_glyph_info_t glyphs[ROWNO][COLNO]; /* Saved glyph numbers. */
79 unsigned long image_width; /* dimensions of tile image */
80 unsigned long image_height;
82 int square_width, /* Saved tile information so */
83 square_height, /* we can calculate the correct */
84 square_ascent, /* placement of changes. */
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. */
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;
100 * Information specific to a message window.
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 */
110 XFontStruct *fs; /* Font for the window. */
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 */
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. */
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. */
133 * Information specific to a "text" status window.
135 struct status_info_t {
136 struct text_buffer text; /* Just a text buffer. */
140 * Information specific to a menu window. First a structure for each
141 * menu entry, then the structure for each menu window.
143 typedef struct x11_mi {
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. */
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. */
167 struct menu curr_menu; /* Menu being displayed. */
168 struct menu new_menu; /* New menu being built. */
170 XFontStruct *fs; /* Font for the window. */
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 */
189 * Information specific to a text window.
192 struct text_buffer text;
193 XFontStruct *fs; /* Font for the text window. */
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. */
209 * Basic window structure.
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.*/
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 */
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
237 #define MAX_WINDOWS 20 /* max number of open windows */
239 #define NHW_NONE 0 /* Unallocated window type. Must be */
240 /* different from any other NHW_* type. */
242 #define NO_CLICK 0 /* No click occurred on the map window. Must */
243 /* be different than CLICK_1 and CLICK_2. */
245 #define DEFAULT_MESSAGE_WIDTH 60 /* width in chars of the message window */
247 #define DISPLAY_FILE_SIZE 35 /* Max number of lines in the default */
248 /* file display window. */
250 #define MAX_KEY_STRING 64 /* String size for converting a keypress */
251 /* event into a character(s) */
253 #define DEFAULT_LINES_DISPLAYED 12 /* # of lines displayed message window */
254 #define MAX_HISTORY 60 /* max history saved on message window */
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;
271 Boolean message_line;
272 Boolean double_tile_size; /* double tile size */
273 String tile_file; /* name of file to open for tiles */
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 */
293 E AppResources appResources;
294 E void (*input_func)();
296 extern struct window_procs X11_procs;
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__, \
305 /* ### dialogs.c ### */
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));
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 *));
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 *));
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));
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 *));
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 */
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);
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 *));
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));
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));
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);
424 E void FDECL(X11_cliparound, (int, int));
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);
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);
443 #ifdef GRAPHIC_TOMBSTONE
444 E void FDECL(X11_outrip, (winid, int, time_t));
446 E void FDECL(genl_outrip, (winid, int, time_t));
449 E void FDECL(X11_preference_update, (const char *));