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. */
10 extern struct window_procs curses_procs
;
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);
19 extern struct window_procs Qt_procs
;
23 * GTK interface (By issei@guru.gr.jp)
25 extern struct window_procs GTK_procs
;
26 extern void win_GTK_init(void);
32 extern struct window_procs mac_procs
;
35 extern struct window_procs beos_procs
;
36 extern void be_win_init(void);
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);
44 extern struct window_procs win32_procs
;
48 extern struct window_procs Gnome_procs
;
52 extern struct window_procs sdlgl_hardw_procs
;
56 extern struct window_procs sdlgl_softw_procs
;
60 extern struct window_procs proxy_procs
;
61 extern void win_proxy_init(void);
64 extern struct window_procs mswin_procs
;
67 STATIC_DCL
void def_raw_print(const char *s
);
72 NEARDATA
struct window_procs windowprocs
;
76 struct window_procs
*procs
;
77 void (*ini_routine
)(void); /* optional (can be 0(void) */
80 { &tty_procs
, win_tty_init
},
82 #ifdef CURSES_GRAPHICS
86 { &X11_procs
, win_X11_init
},
92 { >K_procs
, win_GTK_init
},
95 { &Gem_procs
, win_Gem_init
},
101 { &beos_procs
, be_win_init
},
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 */
107 #ifdef WIN32_GRAPHICS
110 #ifdef GNOME_GRAPHICS
114 { &sdlgl_hardw_procs
, 0 },
117 { &sdlgl_softw_procs
, 0 },
119 #ifdef PROXY_GRAPHICS
120 { &proxy_procs
, win_proxy_init
},
122 #ifdef MSWIN_GRAPHICS
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.
134 genl_message_menu(int let
,
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
150 Just return in this genl one. */
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.
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 */
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);
224 static void hup_cliparound(int, int);
227 static void hup_change_color(int, long, int);
229 static short hup_set_font_name(winid
, char *);
231 static char *hup_get_color_string(void);
232 #endif /* CHANGE_COLOR */
233 static void hup_status_update(int, void *, int, int, int,
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
= {
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 */
263 (void (*)(char *)) hup_void_fdecl_constchar_p
, /* update_positionbar */
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 */
276 hup_void_fdecl_int
, /* change_background */
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 */
290 nhwindows_hangup(void)
292 char *(*previnterface_getmsghistory
)(boolean
) = 0;
295 /* command processor shouldn't look for 2nd char after seeing ESC */
296 iflags
.altmeta
= FALSE
;
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
;
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;
326 return '\033'; /* ESC */
331 hup_yn_function(const char *prompt
,
342 hup_nh_poskey(int *x
, int *y
, int *mod
)
349 hup_getlin(const char *prompt
, char *outbuf
)
351 strcpy(outbuf
, "\033");
356 hup_init_nhwindows(int *argc_p
, char **argv
)
358 iflags
.window_inited
= 1;
363 hup_create_nhwindow(int type
)
370 hup_select_menu(winid window
, int how
,
371 struct mi
**menu_list
)
378 hup_add_menu(winid window
,
380 const anything
*identifier
,
392 hup_end_menu(winid window
, const char *prompt
)
399 hup_putstr(winid window
, int attr
, const char *text
)
406 hup_print_glyph(winid window
,
415 hup_outrip(winid tmpwin
, int how
)
422 hup_curs(winid window
, int x
, int y
)
429 hup_display_nhwindow(winid window
, int blocking
)
436 hup_display_file(const char *fname
, int complain
)
444 hup_cliparound(int x
, int y
)
453 hup_change_color(int color
, int reverse
, long rgb
)
461 hup_set_font_name(winid window
, char *fontname
)
468 hup_get_color_string(void)
472 #endif /* CHANGE_COLOR */
476 hup_status_update(int idx
, void * ptr
, int chg
,
478 unsigned long *colormasks
)
484 * Non-specific stubs.
501 hup_void_fdecl_int(int arg
)
508 hup_void_fdecl_winid(winid window
)
515 hup_void_fdecl_winid_ulong(winid window
,
516 unsigned long mbehavior
)
523 hup_void_fdecl_constchar_p(const char *string
)
528 #endif /* HANGUPHANDLING */
538 static int windows_lock
= FALSE
;
544 int retval
= windows_lock
;
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
)();
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
);