Blindfold removal fix
[slashemextended.git] / src / windows.c
blobd310d37f207639eeb6ce80d3f22e402815fe719c
1 /* SCCS Id: @(#)windows.c 3.4 1996/05/19 */
2 /* Copyright (c) D. Cohrs, 1993. */
3 /* NetHack may be freely redistributed. See license for details. */
5 #include "hack.h"
6 #ifdef TTY_GRAPHICS
7 #include "wintty.h"
8 #endif
9 #ifdef CURSES_GRAPHICS
10 extern struct window_procs curses_procs;
11 #endif
12 #ifdef X11_GRAPHICS
13 /* cannot just blindly include winX.h without including all of X11 stuff */
14 /* and must get the order of include files right. Don't bother */
15 extern struct window_procs X11_procs;
16 extern void win_X11_init(void);
17 #endif
18 #ifdef QT_GRAPHICS
19 extern struct window_procs Qt_procs;
20 #endif
21 #ifdef GTK_GRAPHICS
23 * GTK interface (By issei@guru.gr.jp)
25 extern struct window_procs GTK_procs;
26 extern void win_GTK_init(void);
27 #endif
28 #ifdef GEM_GRAPHICS
29 #include "wingem.h"
30 #endif
31 #ifdef MAC
32 extern struct window_procs mac_procs;
33 #endif
34 #ifdef BEOS_GRAPHICS
35 extern struct window_procs beos_procs;
36 extern void be_win_init(void);
37 #endif
38 #ifdef AMIGA_INTUITION
39 extern struct window_procs amii_procs;
40 extern struct window_procs amiv_procs;
41 extern void ami_wininit_data(void);
42 #endif
43 #ifdef WIN32_GRAPHICS
44 extern struct window_procs win32_procs;
45 #endif
46 #ifdef GNOME_GRAPHICS
47 #include "winGnome.h"
48 extern struct window_procs Gnome_procs;
49 #endif
50 #ifdef GL_GRAPHICS
51 #include "winGL.h"
52 extern struct window_procs sdlgl_hardw_procs;
53 #endif
54 #ifdef SDL_GRAPHICS
55 #include "winGL.h"
56 extern struct window_procs sdlgl_softw_procs;
57 #endif
58 #ifdef PROXY_GRAPHICS
59 #include "winproxy.h"
60 extern struct window_procs proxy_procs;
61 extern void win_proxy_init(void);
62 #endif
63 #ifdef MSWIN_GRAPHICS
64 extern struct window_procs mswin_procs;
65 #endif
67 STATIC_DCL void def_raw_print(const char *s);
69 #ifdef HANGUPHANDLING
70 volatile
71 #endif
72 NEARDATA struct window_procs windowprocs;
74 static
75 struct win_choices {
76 struct window_procs *procs;
77 void (*ini_routine)(void); /* optional (can be 0(void) */
78 } winchoices[] = {
79 #ifdef TTY_GRAPHICS
80 { &tty_procs, win_tty_init },
81 #endif
82 #ifdef CURSES_GRAPHICS
83 { &curses_procs, 0 },
84 #endif
85 #ifdef X11_GRAPHICS
86 { &X11_procs, win_X11_init },
87 #endif
88 #ifdef QT_GRAPHICS
89 { &Qt_procs, 0 },
90 #endif
91 #ifdef GTK_GRAPHICS
92 { &GTK_procs, win_GTK_init },
93 #endif
94 #ifdef GEM_GRAPHICS
95 { &Gem_procs, win_Gem_init },
96 #endif
97 #ifdef MAC
98 { &mac_procs, 0 },
99 #endif
100 #ifdef BEOS_GRAPHICS
101 { &beos_procs, be_win_init },
102 #endif
103 #ifdef AMIGA_INTUITION
104 { &amii_procs, ami_wininit_data }, /* Old font version of the game */
105 { &amiv_procs, ami_wininit_data }, /* Tile version of the game */
106 #endif
107 #ifdef WIN32_GRAPHICS
108 { &win32_procs, 0 },
109 #endif
110 #ifdef GNOME_GRAPHICS
111 { &Gnome_procs, 0 },
112 #endif
113 #ifdef GL_GRAPHICS
114 { &sdlgl_hardw_procs, 0 },
115 #endif
116 #ifdef SDL_GRAPHICS
117 { &sdlgl_softw_procs, 0 },
118 #endif
119 #ifdef PROXY_GRAPHICS
120 { &proxy_procs, win_proxy_init },
121 #endif
122 #ifdef MSWIN_GRAPHICS
123 { &mswin_procs, 0 },
124 #endif
125 { 0, 0 } /* must be last */
129 * tty_message_menu() provides a means to get feedback from the
130 * --More-- prompt; other interfaces generally don't need that.
132 /*ARGSUSED*/
133 char
134 genl_message_menu(int let,
135 int how,
136 const char *mesg)
138 pline("%s", mesg);
139 return 0;
142 /*ARGSUSED*/
143 void
144 genl_preference_update(const char *pref)
146 /* window ports are expected to provide
147 their own preference update routine
148 for the preference capabilities that
149 they support.
150 Just return in this genl one. */
151 return;
154 char *
155 genl_getmsghistory(boolean init)
157 /* window ports can provide
158 their own getmsghistory() routine to
159 preserve message history between games.
160 The routine is called repeatedly from
161 the core save routine, and the window
162 port is expected to successively return
163 each message that it wants saved, starting
164 with the oldest message first, finishing
165 with the most recent.
166 Return null pointer when finished.
168 return (char *) 0;
171 void
172 genl_putmsghistory(const char *msg, boolean is_restoring)
174 /* window ports can provide
175 their own putmsghistory() routine to
176 load message history from a saved game.
177 The routine is called repeatedly from
178 the core restore routine, starting with
179 the oldest saved message first, and
180 finishing with the latest.
181 The window port routine is expected to
182 load the message recall buffers in such
183 a way that the ordering is preserved.
184 The window port routine should make no
185 assumptions about how many messages are
186 forthcoming, nor should it assume that
187 another message will follow this one,
188 so it should keep all pointers/indexes
189 intact at the end of each call.
192 /* this doesn't provide for reloading the message window with the
193 previous session's messages upon restore, but it does put the quest
194 message summary lines there by treating them as ordinary messages */
195 if (!is_restoring)
196 pline("%s", msg);
197 return;
200 #ifdef HANGUPHANDLING
202 * Dummy windowing scheme used to replace current one with no-ops
203 * in order to avoid all terminal I/O after hangup/disconnect.
206 static int hup_nhgetch(void);
207 static char hup_yn_function(const char *, const char *, int);
208 static int hup_nh_poskey(int *, int *, int *);
209 static void hup_getlin(const char *, char *);
210 static void hup_init_nhwindows(int *, char **);
211 static void hup_exit_nhwindows(const char *);
212 static winid hup_create_nhwindow(int);
213 static int hup_select_menu(winid, int, MENU_ITEM_P **);
214 static void hup_add_menu(winid, int, const anything *, int,
215 int, int, const char *, int);
216 static void hup_end_menu(winid, const char *);
217 static void hup_putstr(winid, int, const char *);
218 static void hup_print_glyph(winid, int, int, int);
219 static void hup_outrip(winid, int);
220 static void hup_curs(winid, int, int);
221 static void hup_display_nhwindow(winid, int);
222 static void hup_display_file(const char *, int);
223 #ifdef CLIPPING
224 static void hup_cliparound(int, int);
225 #endif
226 #ifdef CHANGE_COLOR
227 static void hup_change_color(int, long, int);
228 #ifdef MAC
229 static short hup_set_font_name(winid, char *);
230 #endif
231 static char *hup_get_color_string(void);
232 #endif /* CHANGE_COLOR */
233 static void hup_status_update(int, void *, int, int, int,
234 unsigned long *);
236 static int hup_int_ndecl(void);
237 static void hup_void_ndecl(void);
238 static void hup_void_fdecl_int(int);
239 static void hup_void_fdecl_winid(winid);
240 static void hup_void_fdecl_winid_ulong(winid, unsigned long);
241 static void hup_void_fdecl_constchar_p(const char *);
243 static struct window_procs hup_procs = {
244 "hup", 0L, 0L,
245 hup_init_nhwindows,
246 hup_void_ndecl, /* player_selection */
247 hup_void_ndecl, /* askname */
248 hup_void_ndecl, /* get_nh_event */
249 hup_exit_nhwindows, hup_void_fdecl_constchar_p, /* suspend_nhwindows */
250 hup_void_ndecl, /* resume_nhwindows */
251 hup_create_nhwindow, hup_void_fdecl_winid, /* clear_nhwindow */
252 hup_display_nhwindow, hup_void_fdecl_winid, /* destroy_nhwindow */
253 hup_curs, hup_putstr,
254 hup_display_file, hup_void_fdecl_winid, /* start_menu */
255 hup_add_menu, hup_end_menu, hup_select_menu, genl_message_menu,
256 hup_void_ndecl, /* update_inventory */
257 hup_void_ndecl, /* mark_synch */
258 hup_void_ndecl, /* wait_synch */
259 #ifdef CLIPPING
260 hup_cliparound,
261 #endif
262 #ifdef POSITIONBAR
263 (void (*)(char *)) hup_void_fdecl_constchar_p, /* update_positionbar */
264 #endif
265 hup_print_glyph,
266 hup_void_fdecl_constchar_p, /* raw_print */
267 hup_void_fdecl_constchar_p, /* raw_print_bold */
268 hup_nhgetch, hup_nh_poskey, hup_void_ndecl, /* nhbell */
269 hup_int_ndecl, /* doprev_message */
270 hup_yn_function, hup_getlin, hup_int_ndecl, /* get_ext_cmd */
271 hup_void_fdecl_int, /* number_pad */
272 hup_void_ndecl, /* delay_output */
273 #ifdef CHANGE_COLOR
274 hup_change_color,
275 #ifdef MAC
276 hup_void_fdecl_int, /* change_background */
277 hup_set_font_name,
278 #endif
279 hup_get_color_string,
280 #endif /* CHANGE_COLOR */
281 hup_void_ndecl, /* start_screen */
282 hup_void_ndecl, /* end_screen */
283 hup_outrip, genl_preference_update,
286 static void (*previnterface_exit_nhwindows)(const char *) = 0;
288 /* hangup has occurred; switch to no-op user interface */
289 void
290 nhwindows_hangup(void)
292 char *(*previnterface_getmsghistory)(boolean) = 0;
294 #ifdef ALTMETA
295 /* command processor shouldn't look for 2nd char after seeing ESC */
296 iflags.altmeta = FALSE;
297 #endif
299 /* don't call exit_nhwindows() directly here; if a hangup occurs
300 while interface code is executing, exit_nhwindows could knock
301 the interface's active data structures out from under itself */
302 if (iflags.window_inited
303 && windowprocs.win_exit_nhwindows != hup_exit_nhwindows)
304 previnterface_exit_nhwindows = windowprocs.win_exit_nhwindows;
306 windowprocs = hup_procs;
309 static void
310 hup_exit_nhwindows(const char *lastgasp)
312 /* core has called exit_nhwindows(); call the previous interface's
313 shutdown routine now; xxx_exit_nhwindows() needs to call other
314 xxx_ routines directly rather than through windowprocs pointers */
315 if (previnterface_exit_nhwindows) {
316 lastgasp = 0; /* don't want exit routine to attempt extra output */
317 (*previnterface_exit_nhwindows)(lastgasp);
318 previnterface_exit_nhwindows = 0;
320 iflags.window_inited = 0;
323 static int
324 hup_nhgetch(void)
326 return '\033'; /* ESC */
329 /*ARGSUSED*/
330 static char
331 hup_yn_function(const char *prompt,
332 const char *resp,
333 int deflt)
335 if (!deflt)
336 deflt = '\033';
337 return deflt;
340 /*ARGSUSED*/
341 static int
342 hup_nh_poskey(int *x, int *y, int *mod)
344 return '\033';
347 /*ARGSUSED*/
348 static void
349 hup_getlin(const char *prompt, char *outbuf)
351 strcpy(outbuf, "\033");
354 /*ARGSUSED*/
355 static void
356 hup_init_nhwindows(int *argc_p, char **argv)
358 iflags.window_inited = 1;
361 /*ARGUSED*/
362 static winid
363 hup_create_nhwindow(int type)
365 return WIN_ERR;
368 /*ARGSUSED*/
369 static int
370 hup_select_menu(winid window, int how,
371 struct mi **menu_list)
373 return -1;
376 /*ARGSUSED*/
377 static void
378 hup_add_menu(winid window,
379 int intglyphinfo,
380 const anything *identifier,
381 int sel,
382 int grpsel,
383 int attr,
384 const char *txt,
385 int itemflags)
387 return;
390 /*ARGSUSED*/
391 static void
392 hup_end_menu(winid window, const char *prompt)
394 return;
397 /*ARGSUSED*/
398 static void
399 hup_putstr(winid window, int attr, const char *text)
401 return;
404 /*ARGSUSED*/
405 static void
406 hup_print_glyph(winid window,
407 int x, int y,
408 int glyphinfo)
410 return;
413 /*ARGSUSED*/
414 static void
415 hup_outrip(winid tmpwin, int how)
417 return;
420 /*ARGSUSED*/
421 static void
422 hup_curs(winid window, int x, int y)
424 return;
427 /*ARGSUSED*/
428 static void
429 hup_display_nhwindow(winid window, int blocking)
431 return;
434 /*ARGSUSED*/
435 static void
436 hup_display_file(const char *fname, int complain)
438 return;
441 #ifdef CLIPPING
442 /*ARGSUSED*/
443 static void
444 hup_cliparound(int x, int y)
446 return;
448 #endif
450 #ifdef CHANGE_COLOR
451 /*ARGSUSED*/
452 static void
453 hup_change_color(int color, int reverse, long rgb)
455 return;
458 #ifdef MAC
459 /*ARGSUSED*/
460 static short
461 hup_set_font_name(winid window, char *fontname)
463 return 0;
465 #endif /* MAC */
467 static char *
468 hup_get_color_string(void)
470 return (char *) 0;
472 #endif /* CHANGE_COLOR */
474 /*ARGSUSED*/
475 static void
476 hup_status_update(int idx, void * ptr, int chg,
477 int pc, int color,
478 unsigned long *colormasks)
480 return;
484 * Non-specific stubs.
487 static int
488 hup_int_ndecl(void)
490 return -1;
493 static void
494 hup_void_ndecl(void)
496 return;
499 /*ARGUSED*/
500 static void
501 hup_void_fdecl_int(int arg)
503 return;
506 /*ARGUSED*/
507 static void
508 hup_void_fdecl_winid(winid window)
510 return;
513 /*ARGUSED*/
514 static void
515 hup_void_fdecl_winid_ulong(winid window,
516 unsigned long mbehavior)
518 return;
521 /*ARGUSED*/
522 static void
523 hup_void_fdecl_constchar_p(const char *string)
525 return;
528 #endif /* HANGUPHANDLING */
530 STATIC_OVL
531 void
532 def_raw_print(s)
533 const char *s;
535 puts(s);
538 static int windows_lock = FALSE;
541 lock_windows(flag)
542 int flag;
544 int retval = windows_lock;
545 windows_lock = flag;
546 return retval;
549 void
550 choose_windows(s)
551 const char *s;
553 register int i;
555 if (windows_lock)
556 return;
558 for(i=0; winchoices[i].procs; i++)
559 if (!strcmpi(s, winchoices[i].procs->name)) {
560 windowprocs = *winchoices[i].procs;
561 if (winchoices[i].ini_routine) (*winchoices[i].ini_routine)();
562 return;
565 if (!windowprocs.win_raw_print)
566 windowprocs.win_raw_print = def_raw_print;
568 raw_printf("Window type %s not recognized. Choices are:", s);
569 for(i=0; winchoices[i].procs; i++)
570 raw_printf(" %s", winchoices[i].procs->name);
572 if (windowprocs.win_raw_print == def_raw_print)
573 terminate(EXIT_SUCCESS);
574 wait_synch();
577 /*windows.c*/