1 /* SCCS Id: @(#)winX.h 3.4 1996/08/18 */
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 */
39 * Information specific to a map window.
41 struct text_map_info_t {
42 unsigned char text[ROWNO][COLNO]; /* Actual displayed screen. */
44 unsigned char colors[ROWNO][COLNO]; /* Color of each character. */
45 GC color_gcs[CLR_MAX], /* GC for each color */
46 inv_color_gcs[CLR_MAX]; /* GC for each inverse color */
47 #define copy_gc color_gcs[NO_COLOR]
48 #define inv_copy_gc inv_color_gcs[NO_COLOR]
50 GC copy_gc, /* Drawing GC */
51 inv_copy_gc; /* Inverse drawing GC */
55 struct tile_map_info_t {
56 unsigned short glyphs[ROWNO][COLNO]; /* Saved glyph numbers. */
59 unsigned long image_width; /* dimensions of tile image */
60 unsigned long image_height;
64 Dimension viewport_width, /* Saved viewport size, so we can */
65 viewport_height; /* clip to cursor on a resize. */
66 unsigned char t_start[ROWNO], /* Starting column for new info. */
67 t_stop[ROWNO]; /* Ending column for new info. */
68 int square_width, /* Saved font/tile information so */
69 square_height, /* we can calculate the correct */
70 square_ascent, /* placement of changes. */
74 struct text_map_info_t *text_map;
75 struct tile_map_info_t *tile_map;
81 * Information specific to a message window.
84 struct line_element *next;
85 char *line; /* char buffer */
86 int buf_length; /* length of buffer */
87 int str_length; /* length of string in buffer */
91 XFontStruct *fs; /* Font for the window. */
92 int num_lines; /* line count */
93 struct line_element *head; /* head of circular line queue */
94 struct line_element *line_here;/* current drawn line position */
95 struct line_element *last_pause;/* point to the line after the prev */
96 /* bottom of screen */
97 struct line_element *last_pause_head;/* pointer to head of previous */
99 GC gc; /* GC for text drawing */
100 int char_width, /* Saved font information so we can */
101 char_height, /* calculate the correct placement */
102 char_ascent, /* of changes. */
104 Dimension viewport_width, /* Saved viewport size, so we can adjust */
105 viewport_height;/* the slider on a resize. */
106 Boolean dirty; /* Lines have been added to the window. */
110 * Information specific to a "text" status window.
112 struct status_info_t {
113 struct text_buffer text; /* Just a text buffer. */
117 * Information specific to a menu window. First a structure for each
118 * menu entry, then the structure for each menu window.
120 typedef struct x11_mi {
122 anything identifier; /* Opaque type to identify this selection */
123 long pick_count; /* specific selection count; -1 if none */
124 char *str; /* The text of the item. */
125 int attr; /* Attribute for the line. */
126 boolean selected; /* Been selected? */
127 char selector; /* Char used to select this entry. */
128 char gselector; /* Group selector. */
132 x11_menu_item *base; /* Starting pointer for item list. */
133 x11_menu_item *last; /* End pointer for item list. */
134 const char *query; /* Query string. */
135 const char *gacc; /* Group accelerators. */
136 int count; /* Number of strings. */
137 String *list_pointer;/* String list. */
138 Boolean *sensitive; /* Active list. */
139 char curr_selector;/* Next keyboard accelerator to assign, */
140 /* if 0, then we're out. */
144 struct menu curr_menu; /* Menu being displayed. */
145 struct menu new_menu; /* New menu being built. */
147 XFontStruct *fs; /* Font for the window. */
148 long menu_count; /* number entered by user */
149 Dimension line_height; /* Total height of a line of text. */
150 Dimension internal_height; /* Internal height between widget & border */
151 Dimension internal_width; /* Internal width between widget & border */
152 short how; /* Menu mode PICK_NONE, PICK_ONE, PICK_ANY */
153 boolean valid_widgets; /* TRUE if widgets have been created. */
154 boolean is_menu; /* Has been confirmed to being a menu window. */
155 boolean is_active; /* TRUE when waiting for user input. */
156 boolean is_up; /* TRUE when window is popped-up. */
157 boolean cancelled; /* Menu has been explicitly cancelled. */
158 boolean counting; /* true when menu_count has a valid value */
162 * Information specific to a text window.
165 struct text_buffer text;
166 XFontStruct *fs; /* Font for the text window. */
167 int max_width; /* Width of widest line so far. */
168 int extra_width, /* Sum of left and right border widths. */
169 extra_height; /* Sum of top and bottom border widths. */
170 boolean blocked; /* */
171 boolean destroy_on_ack; /* Destroy this window when acknowleged. */
172 #ifdef GRAPHIC_TOMBSTONE
173 boolean is_rip; /* This window needs a tombstone. */
179 * Basic window structure.
182 int type; /* type of nethack window */
183 Widget popup; /* direct parent of widget w or viewport */
184 Widget w; /* the widget that does things */
185 Dimension pixel_width; /* window size, in pixels */
186 Dimension pixel_height;
187 int prevx, cursx; /* Cursor position, only used by */
188 int prevy, cursy; /* map and "plain" status windows.*/
191 struct map_info_t *Map_info; /* map window info */
192 struct mesg_info_t *Mesg_info; /* message window info */
193 struct status_info_t *Status_info; /* status window info */
194 struct menu_info_t *Menu_info; /* menu window info */
195 struct text_info_t *Text_info; /* menu window info */
200 /* Defines to use for the window information union. */
201 #define map_information Win_info.Map_info
202 #define mesg_information Win_info.Mesg_info
203 #define status_information Win_info.Status_info
204 #define menu_information Win_info.Menu_info
205 #define text_information Win_info.Text_info
208 #define MAX_WINDOWS 20 /* max number of open windows */
210 #define NHW_NONE 0 /* Unallocated window type. Must be */
211 /* different from any other NHW_* type. */
213 #define NO_CLICK 0 /* No click occured on the map window. Must */
214 /* be different than CLICK_1 and CLICK_2. */
216 #define DEFAULT_MESSAGE_WIDTH 60/* width in chars of the message window */
218 #define DISPLAY_FILE_SIZE 35 /* Max number of lines in the default */
219 /* file display window. */
221 #define MAX_KEY_STRING 64 /* String size for converting a keypress */
222 /* event into a character(s) */
224 #define DEFAULT_LINES_DISPLAYED 12 /* # of lines displayed message window */
225 #define MAX_HISTORY 60 /* max history saved on message window */
228 /* Window variables (winX.c). */
229 E struct xwindow window_list[MAX_WINDOWS];
230 E XtAppContext app_context; /* context of application */
231 E Widget toplevel; /* toplevel widget */
232 E Atom wm_delete_window; /* delete window protocol */
233 E boolean exit_x_event; /* exit condition for event loop */
234 #define EXIT_ON_KEY_PRESS 0 /* valid values for exit_x_event */
235 #define EXIT_ON_KEY_OR_BUTTON_PRESS 1
236 #define EXIT_ON_EXIT 2
237 #define EXIT_ON_SENT_EVENT 3
238 E int click_x, click_y, click_button, updated_inventory;
243 Boolean message_line;
244 Boolean double_tile_size; /* double tile size */
245 String tile_file; /* name of file to open for tiles */
246 String icon; /* name of desired icon */
247 int message_lines; /* number of lines to attempt to show */
248 String pet_mark_bitmap; /* X11 bitmap file used to mark pets */
249 Pixel pet_mark_color; /* color of pet mark */
250 #ifdef GRAPHIC_TOMBSTONE
251 String tombstone; /* name of XPM file for tombstone */
252 int tombtext_x; /* x-coord of center of first tombstone text */
253 int tombtext_y; /* y-coord of center of first tombstone text */
254 int tombtext_dx; /* x-displacement between tombstone line */
255 int tombtext_dy; /* y-displacement between tombstone line */
259 E AppResources appResources;
260 E void (*input_func)();
262 extern struct window_procs X11_procs;
264 /* Check for an invalid window id. */
265 #define check_winid(window) \
266 if ((window) < 0 || (window) >= MAX_WINDOWS) { \
267 panic("illegal windid [%d] in %s at line %d", \
268 window, __FILE__, __LINE__); \
272 /* ### dialogs.c ### */
273 E Widget FDECL(CreateDialog, (Widget, String, XtCallbackProc, XtCallbackProc));
274 E void FDECL(SetDialogPrompt,(Widget, String));
275 E String FDECL(GetDialogResponse,(Widget));
276 E void FDECL(SetDialogResponse,(Widget, String));
277 E void FDECL(positionpopup,(Widget,BOOLEAN_P));
280 E struct xwindow *FDECL(find_widget,(Widget));
281 E Boolean FDECL(nhApproxColor,(Screen*, Colormap, char*, XColor*));
282 E Dimension FDECL(nhFontHeight,(Widget));
283 E char FDECL(key_event_to_char,(XKeyEvent*));
284 E void FDECL(msgkey, (Widget, XtPointer, XEvent*));
285 E void FDECL(nh_XtPopup, (Widget, int, Widget));
286 E void FDECL(nh_XtPopdown, (Widget));
287 E void NDECL(win_X11_init);
288 E void FDECL(nh_keyscroll, (Widget, XEvent*, String*, Cardinal*));
290 /* ### winmesg.c ### */
291 E void FDECL(set_message_slider, (struct xwindow*));
292 E void FDECL(create_message_window,(struct xwindow*, BOOLEAN_P, Widget));
293 E void FDECL(destroy_message_window,(struct xwindow*));
294 E void FDECL(display_message_window, (struct xwindow*));
295 E void FDECL(append_message,(struct xwindow*, const char*));
296 E void FDECL(set_last_pause, (struct xwindow*));
298 /* ### winmap.c ### */
299 E void NDECL(post_process_tiles);
300 E void FDECL(check_cursor_visibility,(struct xwindow*));
301 E void FDECL(display_map_window,(struct xwindow*));
302 E void FDECL(clear_map_window,(struct xwindow*));
303 E void FDECL(map_input, (Widget, XEvent*, String*, Cardinal*));
304 E void FDECL(set_map_size,(struct xwindow*, DIMENSION_P, DIMENSION_P));
305 E void FDECL(create_map_window,(struct xwindow*, BOOLEAN_P, Widget));
306 E void FDECL(destroy_map_window,(struct xwindow*));
307 E int FDECL(x_event,(int));
309 /* ### winmenu.c ### */
310 E void FDECL(menu_delete, (Widget, XEvent*, String*, Cardinal*));
311 E void FDECL(menu_key,(Widget, XEvent*, String*, Cardinal*));
312 E void FDECL(create_menu_window,(struct xwindow*));
313 E void FDECL(destroy_menu_window,(struct xwindow*));
315 /* ### winmisc.c ### */
316 E void FDECL(ps_key,(Widget, XEvent*, String*, Cardinal*)); /* player selection action */
317 E void FDECL(race_key,(Widget, XEvent*, String*, Cardinal*)); /* race selection action */
318 E void FDECL(gend_key, (Widget,XEvent *,String *,Cardinal *)); /* gender */
319 E void FDECL(algn_key, (Widget,XEvent *,String *,Cardinal *)); /* alignment */
320 E void FDECL(ec_delete, (Widget, XEvent*, String*, Cardinal*));
321 E void FDECL(ec_key,(Widget, XEvent*, String*, Cardinal*)); /* extended command action */
323 /* ### winstatus.c ### */
324 E void FDECL(create_status_window,(struct xwindow*, BOOLEAN_P, Widget));
325 E void FDECL(destroy_status_window,(struct xwindow*));
326 E void FDECL(adjust_status,(struct xwindow*, const char*));
327 E void NDECL(null_out_status);
328 E void NDECL(check_turn_events);
330 /* ### wintext.c ### */
331 E void FDECL(delete_text, (Widget, XEvent*, String*, Cardinal*));
332 E void FDECL(dismiss_text,(Widget, XEvent*, String*, Cardinal*));
333 E void FDECL(key_dismiss_text,(Widget, XEvent*, String*, Cardinal*));
334 #ifdef GRAPHIC_TOMBSTONE
335 E void FDECL(rip_dismiss_text,(Widget, XEvent*, String*, Cardinal*));
337 E void FDECL(add_to_text_window,(struct xwindow*, int, const char*));
338 E void FDECL(display_text_window,(struct xwindow*, BOOLEAN_P));
339 E void FDECL(create_text_window,(struct xwindow*));
340 E void FDECL(destroy_text_window,(struct xwindow*));
341 E void FDECL(clear_text_window,(struct xwindow*));
342 E void FDECL(append_text_buffer,(struct text_buffer*, const char*, BOOLEAN_P)); /* text buffer routines */
343 E void FDECL(init_text_buffer,(struct text_buffer*));
344 E void FDECL(clear_text_buffer,(struct text_buffer*));
345 E void FDECL(free_text_buffer,(struct text_buffer*));
346 #ifdef GRAPHIC_TOMBSTONE
347 E void FDECL(calculate_rip_text, (int));
351 /* ### winval.c ### */
352 E Widget FDECL(create_value,(Widget, const char*));
353 E void FDECL(set_name,(Widget, char*));
354 E void FDECL(set_name_width,(Widget, int));
355 E int FDECL(get_name_width,(Widget));
356 E void FDECL(set_value,(Widget, const char*));
357 E void FDECL(set_value_width,(Widget, int));
358 E int FDECL(get_value_width,(Widget));
359 E void FDECL(hilight_value,(Widget));
360 E void FDECL(swap_fg_bg,(Widget));
362 /* external declarations */
363 E void FDECL(X11_init_nhwindows, (int *, char **));
364 E void NDECL(X11_player_selection);
365 E void NDECL(X11_askname);
366 E void NDECL(X11_get_nh_event) ;
367 E void FDECL(X11_exit_nhwindows, (const char *));
368 E void FDECL(X11_suspend_nhwindows, (const char *));
369 E void NDECL(X11_resume_nhwindows);
370 E winid FDECL(X11_create_nhwindow, (int));
371 E void FDECL(X11_clear_nhwindow, (winid));
372 E void FDECL(X11_display_nhwindow, (winid, BOOLEAN_P));
373 E void FDECL(X11_destroy_nhwindow, (winid));
374 E void FDECL(X11_curs, (winid,int,int));
375 E void FDECL(X11_putstr, (winid, int, const char *));
376 E void FDECL(X11_display_file, (const char *, BOOLEAN_P));
377 E void FDECL(X11_start_menu, (winid));
378 E void FDECL(X11_add_menu, (winid,int,const ANY_P *,
379 CHAR_P, CHAR_P, int, const char *, BOOLEAN_P));
380 E void FDECL(X11_end_menu, (winid, const char *));
381 E int FDECL(X11_select_menu, (winid, int, MENU_ITEM_P **));
382 E void NDECL(X11_update_inventory);
383 E void NDECL(X11_mark_synch);
384 E void NDECL(X11_wait_synch);
386 E void FDECL(X11_cliparound, (int, int));
388 E void FDECL(X11_print_glyph, (winid,XCHAR_P,XCHAR_P,int));
389 E void FDECL(X11_raw_print, (const char *));
390 E void FDECL(X11_raw_print_bold, (const char *));
391 E int NDECL(X11_nhgetch);
392 E int FDECL(X11_nh_poskey, (int *, int *, int *));
393 E void NDECL(X11_nhbell);
394 E int NDECL(X11_doprev_message);
395 E char FDECL(X11_yn_function, (const char *, const char *, CHAR_P));
396 E void FDECL(X11_getlin, (const char *,char *));
397 E int NDECL(X11_get_ext_cmd);
398 E void FDECL(X11_number_pad, (int));
399 E void NDECL(X11_delay_output);
401 /* other defs that really should go away (they're tty specific) */
402 E void NDECL(X11_start_screen);
403 E void NDECL(X11_end_screen);
405 #ifdef GRAPHIC_TOMBSTONE
406 E void FDECL(X11_outrip, (winid,int));
408 E void FDECL(genl_outrip, (winid,int));