OSDN Git Service

3a2c8fa4e3d5ab461c67b0a819d3388ca782c1cd
[jnethack/source.git] / include / winX.h
1 /* NetHack 3.6  winX.h  $NHDT-Date: 1457079196 2016/03/04 08:13:16 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.23 $ */
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     boolean preselected; /*   in advance?  */
151     char selector;       /* Char used to select this entry. */
152     char gselector;      /* Group selector. */
153     Widget w;
154     int window;
155 } x11_menu_item;
156
157 struct menu {
158     x11_menu_item *base;  /* Starting pointer for item list. */
159     x11_menu_item *last;  /* End pointer for item list. */
160     const char *query;    /* Query string. */
161     const char *gacc;     /* Group accelerators. */
162     int count;            /* Number of strings. */
163     char curr_selector;   /* Next keyboard accelerator to assign, */
164                           /*   if 0, then we're out.              */
165 };
166
167 struct menu_info_t {
168     struct menu curr_menu; /* Menu being displayed. */
169     struct menu new_menu;  /* New menu being built. */
170
171     XFontStruct *fs;           /* Font for the window. */
172 /*JP*/
173 #ifdef XI18N
174     XFontSet    fontset;
175 #endif
176     long menu_count;           /* number entered by user */
177     Dimension line_height;     /* Total height of a line of text. */
178     Dimension internal_height; /* Internal height between widget & border */
179     Dimension internal_width;  /* Internal width between widget & border */
180     short how;                 /* Menu mode PICK_NONE, PICK_ONE, PICK_ANY */
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     boolean permi;
187     boolean disable_mcolors; /* disable menucolors */
188
189     int permi_x, permi_y; /* perm_invent window x,y */
190     int permi_w, permi_h; /* perm_invent window wid, hei */
191 };
192
193 /*
194  * Information specific to a text window.
195  */
196 struct text_info_t {
197     struct text_buffer text;
198     XFontStruct *fs;        /* Font for the text window. */
199 /*JP*/
200 #ifdef XI18N
201     XFontSet    fontset;
202 #endif
203     int max_width;          /* Width of widest line so far. */
204     int extra_width,        /* Sum of left and right border widths. */
205         extra_height;       /* Sum of top and bottom border widths. */
206     boolean blocked;        /*  */
207     boolean destroy_on_ack; /* Destroy this window when acknowledged. */
208 #ifdef GRAPHIC_TOMBSTONE
209     boolean is_rip; /* This window needs a tombstone. */
210 #endif
211 };
212
213 /*
214  * Basic window structure.
215  */
216 struct xwindow {
217     int type;              /* type of nethack window */
218     Widget popup;          /* direct parent of widget w or viewport */
219     Widget w;              /* the widget that does things */
220     Dimension pixel_width; /* window size, in pixels */
221     Dimension pixel_height;
222     int prevx, cursx; /* Cursor position, only used by    */
223     int prevy, cursy; /*   map and "plain" status windows.*/
224
225     boolean nh_colors_inited;
226     XColor nh_colors[CLR_MAX];
227     XFontStruct *boldfs;       /* Bold font */
228     Display *boldfs_dpy;       /* Bold font display */
229     char *title;
230
231     union {
232         struct map_info_t *Map_info;       /* map window info */
233         struct mesg_info_t *Mesg_info;     /* message window info */
234         struct status_info_t *Status_info; /* status window info */
235         struct menu_info_t *Menu_info;     /* menu window info */
236         struct text_info_t *Text_info;     /* menu window info */
237     } Win_info;
238     boolean keep_window;
239 };
240
241 /* Defines to use for the window information union. */
242 #define map_information Win_info.Map_info
243 #define mesg_information Win_info.Mesg_info
244 #define status_information Win_info.Status_info
245 #define menu_information Win_info.Menu_info
246 #define text_information Win_info.Text_info
247
248 #define MAX_WINDOWS 20 /* max number of open windows */
249
250 #define NHW_NONE 0 /* Unallocated window type.  Must be    */
251                    /* different from any other NHW_* type. */
252
253 #define NO_CLICK 0 /* No click occurred on the map window. Must */
254                    /* be different than CLICK_1 and CLICK_2.    */
255
256 #define DEFAULT_MESSAGE_WIDTH 60 /* width in chars of the message window */
257
258 #define DISPLAY_FILE_SIZE 35 /* Max number of lines in the default */
259                              /* file display window.               */
260
261 #define MAX_KEY_STRING 64 /* String size for converting a keypress */
262                           /* event into a character(s)             */
263
264 #define DEFAULT_LINES_DISPLAYED 12 /* # of lines displayed message window */
265 #define MAX_HISTORY 60             /* max history saved on message window */
266
267 /* Window variables (winX.c). */
268 E struct xwindow window_list[MAX_WINDOWS];
269 E XtAppContext app_context; /* context of application */
270 E Widget toplevel;          /* toplevel widget */
271 E Atom wm_delete_window;    /* delete window protocol */
272 E boolean exit_x_event;     /* exit condition for event loop */
273 #define EXIT_ON_KEY_PRESS 0 /* valid values for exit_x_event */
274 #define EXIT_ON_KEY_OR_BUTTON_PRESS 1
275 #define EXIT_ON_EXIT 2
276 #define EXIT_ON_SENT_EVENT 3
277 E int click_x, click_y, click_button, updated_inventory;
278 E boolean plsel_ask_name;
279
280 typedef struct {
281     Boolean slow;             /* issue prompts between map and message wins */
282     Boolean fancy_status;     /* use "fancy" status vs. TTY-style status */
283     Boolean autofocus;        /* grab pointer focus for popup windows */
284     Boolean message_line;     /* separate current turn mesgs from prev ones */
285     Boolean highlight_prompt; /* if 'slow', highlight yn prompts */
286     Boolean double_tile_size; /* double tile size */
287     String tile_file;         /* name of file to open for tiles */
288 #ifdef X11LARGETILE
289     int     tile_width;
290     int     tile_height;
291 #endif
292     String icon;              /* name of desired icon */
293     int message_lines;        /* number of lines to attempt to show */
294     int extcmd_height_delta;  /* bottom margin for extended command menu */
295     String pet_mark_bitmap;   /* X11 bitmap file used to mark pets */
296     Pixel pet_mark_color;     /* color of pet mark */
297     String pilemark_bitmap;   /* X11 bitmap file used to mark item piles */
298     Pixel pilemark_color;     /* color of item pile mark */
299 #ifdef GRAPHIC_TOMBSTONE
300     String tombstone; /* name of XPM file for tombstone */
301     int tombtext_x;   /* x-coord of center of first tombstone text */
302     int tombtext_y;   /* y-coord of center of first tombstone text */
303     int tombtext_dx;  /* x-displacement between tombstone line */
304     int tombtext_dy;  /* y-displacement between tombstone line */
305 #endif
306 } AppResources;
307
308 E AppResources appResources;
309 E void (*input_func)();
310
311 extern struct window_procs X11_procs;
312
313 /* Check for an invalid window id. */
314 #define check_winid(window)                                             \
315     if ((window) < 0 || (window) >= MAX_WINDOWS) {                      \
316         panic("illegal windid [%d] in %s at line %d", window, __FILE__, \
317               __LINE__);                                                \
318     }
319
320 /* ### dialogs.c ### */
321 E Widget
322 FDECL(CreateDialog, (Widget, String, XtCallbackProc, XtCallbackProc));
323 E void FDECL(SetDialogPrompt, (Widget, String));
324 E String FDECL(GetDialogResponse, (Widget));
325 E void FDECL(SetDialogResponse, (Widget, String, unsigned));
326 E void FDECL(positionpopup, (Widget, BOOLEAN_P));
327
328 /* ### winX.c ### */
329 E struct xwindow *FDECL(find_widget, (Widget));
330 E XColor FDECL(get_nhcolor, (struct xwindow *, int));
331 E void FDECL(init_menu_nhcolors, (struct xwindow *));
332 E void FDECL(load_boldfont, (struct xwindow *, Widget));
333 E Boolean FDECL(nhApproxColor, (Screen *, Colormap, char *, XColor *));
334 E void FDECL(get_widget_window_geometry, (Widget, int *, int *, int *, int *));
335 E char *FDECL(fontname_boldify, (const char *));
336 E Dimension FDECL(nhFontHeight, (Widget));
337 E char FDECL(key_event_to_char, (XKeyEvent *));
338 E void FDECL(msgkey, (Widget, XtPointer, XEvent *));
339 E void FDECL(highlight_yn, (BOOLEAN_P));
340 E void FDECL(nh_XtPopup, (Widget, int, Widget));
341 E void FDECL(nh_XtPopdown, (Widget));
342 E void FDECL(win_X11_init, (int));
343 E void FDECL(find_scrollbars, (Widget, Widget *, Widget *));
344 E void FDECL(nh_keyscroll, (Widget, XEvent *, String *, Cardinal *));
345
346 /* ### winmesg.c ### */
347 E void FDECL(set_message_slider, (struct xwindow *));
348 E void FDECL(create_message_window, (struct xwindow *, BOOLEAN_P, Widget));
349 E void FDECL(destroy_message_window, (struct xwindow *));
350 E void FDECL(display_message_window, (struct xwindow *));
351 E void FDECL(append_message, (struct xwindow *, const char *));
352 E void FDECL(set_last_pause, (struct xwindow *));
353
354 /* ### winmap.c ### */
355 E void NDECL(post_process_tiles);
356 E void FDECL(check_cursor_visibility, (struct xwindow *));
357 E void FDECL(display_map_window, (struct xwindow *));
358 E void FDECL(clear_map_window, (struct xwindow *));
359 E void FDECL(map_input, (Widget, XEvent *, String *, Cardinal *));
360 E void FDECL(set_map_size, (struct xwindow *, DIMENSION_P, DIMENSION_P));
361 E void FDECL(create_map_window, (struct xwindow *, BOOLEAN_P, Widget));
362 E void FDECL(destroy_map_window, (struct xwindow *));
363 E int FDECL(x_event, (int));
364
365 /* ### winmenu.c ### */
366 E void FDECL(menu_delete, (Widget, XEvent *, String *, Cardinal *));
367 E void FDECL(menu_key, (Widget, XEvent *, String *, Cardinal *));
368 E void FDECL(create_menu_window, (struct xwindow *));
369 E void FDECL(destroy_menu_window, (struct xwindow *));
370
371 /* ### winmisc.c ### */
372 E void FDECL(ps_key, (Widget, XEvent *, String *,
373                       Cardinal *)); /* player selection action */
374 E void FDECL(race_key, (Widget, XEvent *, String *,
375                         Cardinal *)); /* race selection action */
376 E void FDECL(gend_key, (Widget, XEvent *, String *, Cardinal *)); /* gender */
377 E void FDECL(algn_key,
378              (Widget, XEvent *, String *, Cardinal *)); /* alignment */
379 E void FDECL(ec_delete, (Widget, XEvent *, String *, Cardinal *));
380 E void FDECL(ec_key, (Widget, XEvent *, String *,
381                       Cardinal *)); /* extended command action */
382 E void FDECL(plsel_quit, (Widget, XEvent *, String *,
383                       Cardinal *)); /* player selection dialog */
384 E void FDECL(plsel_play, (Widget, XEvent *, String *,
385                       Cardinal *)); /* player selection dialog */
386 E void FDECL(plsel_randomize, (Widget, XEvent *, String *,
387                       Cardinal *)); /* player selection dialog */
388 E void NDECL(release_extended_cmds);
389
390 /* ### winstatus.c ### */
391 E void FDECL(create_status_window, (struct xwindow *, BOOLEAN_P, Widget));
392 E void FDECL(destroy_status_window, (struct xwindow *));
393 E void FDECL(adjust_status, (struct xwindow *, const char *));
394 E void NDECL(null_out_status);
395 E void NDECL(check_turn_events);
396
397 /* ### wintext.c ### */
398 E void FDECL(delete_text, (Widget, XEvent *, String *, Cardinal *));
399 E void FDECL(dismiss_text, (Widget, XEvent *, String *, Cardinal *));
400 E void FDECL(key_dismiss_text, (Widget, XEvent *, String *, Cardinal *));
401 #ifdef GRAPHIC_TOMBSTONE
402 E void FDECL(rip_dismiss_text, (Widget, XEvent *, String *, Cardinal *));
403 #endif
404 E void FDECL(add_to_text_window, (struct xwindow *, int, const char *));
405 E void FDECL(display_text_window, (struct xwindow *, BOOLEAN_P));
406 E void FDECL(create_text_window, (struct xwindow *));
407 E void FDECL(destroy_text_window, (struct xwindow *));
408 E void FDECL(clear_text_window, (struct xwindow *));
409 E void FDECL(append_text_buffer, (struct text_buffer *, const char *,
410                                   BOOLEAN_P)); /* text buffer routines */
411 E void FDECL(init_text_buffer, (struct text_buffer *));
412 E void FDECL(clear_text_buffer, (struct text_buffer *));
413 E void FDECL(free_text_buffer, (struct text_buffer *));
414 #ifdef GRAPHIC_TOMBSTONE
415 E void FDECL(calculate_rip_text, (int, time_t));
416 #endif
417
418 /* ### winval.c ### */
419 E Widget FDECL(create_value, (Widget, const char *));
420 E void FDECL(set_name, (Widget, const char *));
421 E void FDECL(set_name_width, (Widget, int));
422 E int FDECL(get_name_width, (Widget));
423 E void FDECL(set_value, (Widget, const char *));
424 E void FDECL(set_value_width, (Widget, int));
425 E int FDECL(get_value_width, (Widget));
426 E void FDECL(hilight_value, (Widget));
427 E void FDECL(swap_fg_bg, (Widget));
428
429 /* external declarations */
430 E char *FDECL(X11_getmsghistory, (BOOLEAN_P));
431 E void FDECL(X11_putmsghistory, (const char *, BOOLEAN_P));
432 E void FDECL(X11_init_nhwindows, (int *, char **));
433 E void NDECL(X11_player_selection);
434 E void NDECL(X11_askname);
435 E void NDECL(X11_get_nh_event);
436 E void FDECL(X11_exit_nhwindows, (const char *));
437 E void FDECL(X11_suspend_nhwindows, (const char *));
438 E void NDECL(X11_resume_nhwindows);
439 E winid FDECL(X11_create_nhwindow, (int));
440 E void FDECL(X11_clear_nhwindow, (winid));
441 E void FDECL(X11_display_nhwindow, (winid, BOOLEAN_P));
442 E void FDECL(X11_destroy_nhwindow, (winid));
443 E void FDECL(X11_curs, (winid, int, int));
444 E void FDECL(X11_putstr, (winid, int, const char *));
445 E void FDECL(X11_display_file, (const char *, BOOLEAN_P));
446 E void FDECL(X11_start_menu, (winid));
447 E void FDECL(X11_add_menu, (winid, int, const ANY_P *, CHAR_P, CHAR_P, int,
448                             const char *, BOOLEAN_P));
449 E void FDECL(X11_end_menu, (winid, const char *));
450 E int FDECL(X11_select_menu, (winid, int, MENU_ITEM_P **));
451 E void NDECL(X11_update_inventory);
452 E void NDECL(X11_mark_synch);
453 E void NDECL(X11_wait_synch);
454 #ifdef CLIPPING
455 E void FDECL(X11_cliparound, (int, int));
456 #endif
457 E void FDECL(X11_print_glyph, (winid, XCHAR_P, XCHAR_P, int, int));
458 E void FDECL(X11_raw_print, (const char *));
459 E void FDECL(X11_raw_print_bold, (const char *));
460 E int NDECL(X11_nhgetch);
461 E int FDECL(X11_nh_poskey, (int *, int *, int *));
462 E void NDECL(X11_nhbell);
463 E int NDECL(X11_doprev_message);
464 E char FDECL(X11_yn_function, (const char *, const char *, CHAR_P));
465 E void FDECL(X11_getlin, (const char *, char *));
466 E int NDECL(X11_get_ext_cmd);
467 E void FDECL(X11_number_pad, (int));
468 E void NDECL(X11_delay_output);
469 E void NDECL(X11_status_init);
470 E void NDECL(X11_status_finish);
471 E void FDECL(X11_status_enablefield, (int, const char *, const char *, BOOLEAN_P));
472 E void FDECL(X11_status_update, (int, genericptr_t, int, int, int, unsigned long *));
473
474 /* other defs that really should go away (they're tty specific) */
475 E void NDECL(X11_start_screen);
476 E void NDECL(X11_end_screen);
477
478 #ifdef GRAPHIC_TOMBSTONE
479 E void FDECL(X11_outrip, (winid, int, time_t));
480 #else
481 E void FDECL(genl_outrip, (winid, int, time_t));
482 #endif
483
484 E void FDECL(X11_preference_update, (const char *));
485
486 #endif /* WINX_H */