Build Fix -- compatibility issue with newer autoconf
[sxemacs] / src / ui / console.h
1 /* Define console object for XEmacs.
2    Copyright (C) 1996 Ben Wing
3
4 This file is part of SXEmacs
5
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
18
19
20 /* Synched up with: Not in FSF. */
21
22 /* Written by Ben Wing. */
23
24 #ifndef INCLUDED_console_h_
25 #define INCLUDED_console_h_
26
27 /* Devices and consoles are similar entities.  The idea is that
28    a console represents a physical keyboard/mouse/other-input-source
29    while a device represents a display where frames appear on.
30    In the X world, a console is a "Display" while a device is a
31    "Screen".  Implementationally, it can sometimes get confusing:
32    under X, multiple devices on a single console are different
33    "Display" connections to what is in reality the same Display on
34    the same server.  Because of this, input comes from the device
35    and not from the console.  This is OK because events are basically
36    always tagged to a particular X window (i.e. frame),
37    which exists on only one screen; therefore the event won't be
38    reported multiple times even if there are multiple devices on
39    the same physical display.  This is an implementation detail
40    specific to X consoles (e.g. under NeXTstep or Windows, this
41    could be different, and input would come directly from the console).
42 */
43
44 /* GCC does not like forward enum declaration. This needs to be
45    defined here. What a disgust! */
46
47 enum device_metrics {
48         DM_color_default, DM_color_select, DM_color_balloon, DM_color_3d_face,
49         DM_color_3d_light, DM_color_3d_dark, DM_color_menu,
50             DM_color_menu_highlight,
51         DM_color_menu_button, DM_color_menu_disabled, DM_color_toolbar,
52         DM_color_scrollbar, DM_color_desktop, DM_color_workspace,
53             DM_font_default,
54         DM_font_menubar, DM_font_dialog, DM_size_cursor, DM_size_scrollbar,
55         DM_size_menu, DM_size_toolbar, DM_size_toolbar_button,
56         DM_size_toolbar_border, DM_size_icon, DM_size_icon_small,
57             DM_size_device,
58         DM_size_workspace, DM_offset_workspace, DM_size_device_mm,
59             DM_device_dpi,
60         DM_num_bit_planes, DM_num_color_cells, DM_mouse_buttons,
61             DM_swap_buttons,
62         DM_show_sounds, DM_slow_device, DM_security
63 };
64
65 extern const struct struct_description cted_description;
66 extern const struct struct_description console_methods_description;
67
68 /*
69  * Constants returned by device_implementation_flags_method
70  */
71
72 /* Set when device uses pixel-based geometry */
73 #define XDEVIMPF_PIXEL_GEOMETRY         0x00000001L
74
75 /* Indicates that the device is a printer */
76 #define XDEVIMPF_IS_A_PRINTER           0x00000002L
77
78 /* Do not automatically redisplay this device */
79 #define XDEVIMPF_NO_AUTO_REDISPLAY      0x00000004L
80
81 /* Do not delete the device when last frame's gone */
82 #define XDEVIMPF_FRAMELESS_OK           0x00000008L
83
84 /* Do not preempt resiaply of frame or device once it starts */
85 #define XDEVIMPF_DONT_PREEMPT_REDISPLAY 0x00000010L
86
87 struct console_methods {
88         const char *name;       /* Used by print_console, print_device, print_frame */
89         Lisp_Object symbol;
90         Lisp_Object predicate_symbol;
91         unsigned int flags;     /* Read-only implementation flags, set once upon
92                                    console type creation. INITIALIZE_CONSOLE_TYPE sets
93                                    this member to 0. */
94
95         /* console methods */
96         void (*init_console_method) (struct console *, Lisp_Object props);
97         void (*mark_console_method) (struct console *);
98         int (*initially_selected_for_input_method) (struct console *);
99         void (*delete_console_method) (struct console *);
100          Lisp_Object(*semi_canonicalize_console_connection_method)
101          (Lisp_Object connection, Error_behavior errb);
102          Lisp_Object(*semi_canonicalize_device_connection_method)
103          (Lisp_Object connection, Error_behavior errb);
104          Lisp_Object(*canonicalize_console_connection_method)
105          (Lisp_Object connection, Error_behavior errb);
106          Lisp_Object(*canonicalize_device_connection_method)
107          (Lisp_Object connection, Error_behavior errb);
108          Lisp_Object(*device_to_console_connection_method)
109          (Lisp_Object connection, Error_behavior errb);
110
111         /* device methods */
112         void (*init_device_method) (struct device *, Lisp_Object props);
113         void (*finish_init_device_method) (struct device *, Lisp_Object props);
114         void (*delete_device_method) (struct device *);
115         void (*mark_device_method) (struct device *);
116         void (*asynch_device_change_method) (void);
117          Lisp_Object(*device_system_metrics_method) (struct device *,
118                                                      enum device_metrics);
119          Lisp_Object(*own_selection_method) (Lisp_Object selection_name,
120                                              Lisp_Object selection_value,
121                                              Lisp_Object how_to_add,
122                                              Lisp_Object selection_type,
123                                              int owned_p);
124         void (*disown_selection_method) (Lisp_Object selection_name,
125                                          Lisp_Object timeval);
126          Lisp_Object(*get_foreign_selection_method) (Lisp_Object
127                                                      selection_symbol,
128                                                      Lisp_Object target_type);
129          Lisp_Object(*selection_exists_p_method) (Lisp_Object selection_name,
130                                                   Lisp_Object selection_type);
131          Lisp_Object(*available_selection_types_method) (Lisp_Object
132                                                          selection_name);
133          Lisp_Object(*register_selection_data_type_method) (Lisp_Object
134                                                             type_name);
135          Lisp_Object(*selection_data_type_name_method) (Lisp_Object type);
136
137         /* frame methods */
138         Lisp_Object *device_specific_frame_props;
139         void (*init_frame_1_method) (struct frame *, Lisp_Object properties);
140         void (*init_frame_2_method) (struct frame *, Lisp_Object properties);
141         void (*init_frame_3_method) (struct frame *);
142         void (*after_init_frame_method) (struct frame *, int first_on_device,
143                                          int first_on_console);
144         void (*mark_frame_method) (struct frame *);
145         void (*delete_frame_method) (struct frame *);
146         void (*focus_on_frame_method) (struct frame *);
147         void (*raise_frame_method) (struct frame *);
148         void (*lower_frame_method) (struct frame *);
149         void (*enable_frame_method) (struct frame *);
150         void (*disable_frame_method) (struct frame *);
151         int (*get_mouse_position_method) (struct device * d,
152                                           Lisp_Object * frame, int *x, int *y);
153         void (*set_mouse_position_method) (struct window * w, int x, int y);
154         void (*make_frame_visible_method) (struct frame * f);
155         void (*make_frame_invisible_method) (struct frame * f);
156         void (*iconify_frame_method) (struct frame * f);
157          Lisp_Object(*frame_property_method) (struct frame * f,
158                                               Lisp_Object prop);
159         int (*internal_frame_property_p_method) (struct frame * f,
160                                                  Lisp_Object prop);
161          Lisp_Object(*frame_properties_method) (struct frame * f);
162         void (*set_frame_properties_method) (struct frame * f,
163                                              Lisp_Object plist);
164         void (*set_frame_size_method) (struct frame * f, int width, int height);
165         void (*set_frame_position_method) (struct frame * f, int xoff,
166                                            int yoff);
167         int (*frame_visible_p_method) (struct frame * f);
168         int (*frame_totally_visible_p_method) (struct frame * f);
169         int (*frame_iconified_p_method) (struct frame * f);
170         void (*set_title_from_bufbyte_method) (struct frame * f,
171                                                Bufbyte * title);
172         void (*set_icon_name_from_bufbyte_method) (struct frame * f,
173                                                    Bufbyte * title);
174         void (*set_frame_pointer_method) (struct frame * f);
175         void (*set_frame_icon_method) (struct frame * f);
176         void (*popup_menu_method) (Lisp_Object menu, Lisp_Object event);
177          Lisp_Object(*get_frame_parent_method) (struct frame * f);
178         void (*update_frame_external_traits_method) (struct frame * f,
179                                                      Lisp_Object name);
180         int (*frame_size_fixed_p_method) (struct frame * f);
181         void (*eject_page_method) (struct frame * f);
182
183         /* redisplay methods */
184         int (*left_margin_width_method) (struct window *);
185         int (*right_margin_width_method) (struct window *);
186         int (*text_width_method) (struct frame * f, struct face_cachel * cachel,
187                                   const Emchar * str, Charcount len);
188         void (*output_display_block_method) (struct window *,
189                                              struct display_line *, int, int,
190                                              int, int, int, int, int);
191         int (*divider_height_method) (void);
192         int (*eol_cursor_width_method) (void);
193         void (*output_vertical_divider_method) (struct window *, int);
194         void (*clear_to_window_end_method) (struct window *, int, int);
195         void (*clear_region_method) (Lisp_Object, struct device *,
196                                      struct frame *, face_index, int, int, int,
197                                      int, Lisp_Object, Lisp_Object,
198                                      Lisp_Object);
199         void (*clear_frame_method) (struct frame *);
200         void (*window_output_begin_method) (struct window *);
201         void (*frame_output_begin_method) (struct frame *);
202         void (*window_output_end_method) (struct window *);
203         void (*frame_output_end_method) (struct frame *);
204         int (*flash_method) (struct device *);
205         void (*ring_bell_method) (struct device *, int volume, int pitch,
206                                   int duration);
207         void (*frame_redraw_cursor_method) (struct frame * f);
208         void (*set_final_cursor_coords_method) (struct frame *, int, int);
209         void (*bevel_area_method) (struct window *, face_index, int, int, int,
210                                    int, int, int, enum edge_style);
211         void (*output_pixmap_method) (struct window * w,
212                                       Lisp_Object image_instance,
213                                       struct display_box * db,
214                                       struct display_glyph_area * dga,
215                                       face_index findex, int cursor_start,
216                                       int cursor_width, int cursor_height,
217                                       int offset_bitmap);
218         void (*output_string_method) (struct window * w,
219                                       struct display_line * dl,
220                                       Emchar_dynarr * buf, int xpos,
221                                       int xoffset, int start_pixpos, int width,
222                                       face_index findex, int cursor,
223                                       int cursor_start, int cursor_width,
224                                       int cursor_height);
225         /* color methods */
226         int (*initialize_color_instance_method) (Lisp_Color_Instance *,
227                                                  Lisp_Object name,
228                                                  Lisp_Object device,
229                                                  Error_behavior errb);
230         void (*mark_color_instance_method) (Lisp_Color_Instance *);
231         void (*print_color_instance_method) (Lisp_Color_Instance *,
232                                              Lisp_Object printcharfun,
233                                              int escapeflag);
234         void (*finalize_color_instance_method) (Lisp_Color_Instance *);
235         int (*color_instance_equal_method) (Lisp_Color_Instance *,
236                                             Lisp_Color_Instance *, int depth);
237         unsigned long (*color_instance_hash_method) (Lisp_Color_Instance *,
238                                                      int depth);
239          Lisp_Object(*color_instance_rgb_components_method) (Lisp_Color_Instance
240                                                              *);
241         int (*valid_color_name_p_method) (struct device *, Lisp_Object color);
242
243         /* font methods */
244         int (*initialize_font_instance_method) (Lisp_Font_Instance *,
245                                                 Lisp_Object name,
246                                                 Lisp_Object device,
247                                                 Error_behavior errb);
248         void (*mark_font_instance_method) (Lisp_Font_Instance *);
249         void (*print_font_instance_method) (Lisp_Font_Instance *,
250                                             Lisp_Object printcharfun,
251                                             int escapeflag);
252         void (*finalize_font_instance_method) (Lisp_Font_Instance *);
253          Lisp_Object(*font_instance_truename_method) (Lisp_Font_Instance *,
254                                                       Error_behavior errb);
255          Lisp_Object(*font_instance_properties_method) (Lisp_Font_Instance *);
256          Lisp_Object(*list_fonts_method) (Lisp_Object pattern,
257                                           Lisp_Object device);
258          Lisp_Object(*find_charset_font_method) (Lisp_Object device,
259                                                  Lisp_Object font,
260                                                  Lisp_Object charset);
261         int (*font_spec_matches_charset_method) (struct device * d,
262                                                  Lisp_Object charset,
263                                                  const Bufbyte * nonreloc,
264                                                  Lisp_Object reloc,
265                                                  Bytecount offset,
266                                                  Bytecount length);
267
268         /* image methods */
269         void (*mark_image_instance_method) (Lisp_Image_Instance *);
270         void (*print_image_instance_method) (Lisp_Image_Instance *,
271                                              Lisp_Object printcharfun,
272                                              int escapeflag);
273         void (*finalize_image_instance_method) (Lisp_Image_Instance *);
274         void (*unmap_subwindow_method) (Lisp_Image_Instance *);
275         void (*map_subwindow_method) (Lisp_Image_Instance *, int x, int y,
276                                       struct display_glyph_area * dga);
277         void (*resize_subwindow_method) (Lisp_Image_Instance *, int w, int h);
278         void (*redisplay_subwindow_method) (Lisp_Image_Instance *);
279         void (*redisplay_widget_method) (Lisp_Image_Instance *);
280         /* Maybe this should be a specifier. Unfortunately specifiers don't
281            allow us to represent things at the toolkit level, which is what
282            is required here. */
283         int (*widget_border_width_method) (void);
284         int (*widget_spacing_method) (Lisp_Image_Instance *);
285         int (*image_instance_equal_method) (Lisp_Image_Instance *,
286                                             Lisp_Image_Instance *, int depth);
287         unsigned long (*image_instance_hash_method) (Lisp_Image_Instance *,
288                                                      int depth);
289         void (*init_image_instance_from_eimage_method) (Lisp_Image_Instance *
290                                                         ii, int width,
291                                                         int height, int slices,
292                                                         unsigned char *eimage,
293                                                         int dest_mask,
294                                                         Lisp_Object
295                                                         instantiator,
296                                                         Lisp_Object domain);
297          Lisp_Object(*locate_pixmap_file_method) (Lisp_Object file_method);
298         int (*colorize_image_instance_method) (Lisp_Object image_instance,
299                                                Lisp_Object fg, Lisp_Object bg);
300         Lisp_Object image_conversion_list;
301
302 #ifdef HAVE_TOOLBARS
303         /* toolbar methods */
304         void (*output_frame_toolbars_method) (struct frame *);
305         void (*clear_frame_toolbars_method) (struct frame *);
306         void (*initialize_frame_toolbars_method) (struct frame *);
307         void (*free_frame_toolbars_method) (struct frame *);
308         void (*output_toolbar_button_method) (struct frame *, Lisp_Object);
309         void (*redraw_frame_toolbars_method) (struct frame *);
310         void (*redraw_exposed_toolbars_method) (struct frame * f, int x, int y,
311                                                 int width, int height);
312 #endif
313
314 #ifdef HAVE_SCROLLBARS
315         /* scrollbar methods */
316         int (*inhibit_scrollbar_slider_size_change_method) (void);
317         void (*free_scrollbar_instance_method) (struct scrollbar_instance *);
318         void (*release_scrollbar_instance_method) (struct scrollbar_instance *);
319         void (*create_scrollbar_instance_method) (struct frame *, int,
320                                                   struct scrollbar_instance *);
321         void (*update_scrollbar_instance_values_method) (struct window *,
322                                                          struct
323                                                          scrollbar_instance *,
324                                                          int, int, int, int,
325                                                          int, int, int, int,
326                                                          int, int);
327         void (*update_scrollbar_instance_status_method) (struct window *, int,
328                                                          int,
329                                                          struct
330                                                          scrollbar_instance *);
331         void (*scrollbar_pointer_changed_in_window_method) (struct window * w);
332 #ifdef MEMORY_USAGE_STATS
333         int (*compute_scrollbar_instance_usage_method) (struct device *,
334                                                         struct
335                                                         scrollbar_instance *,
336                                                         struct overhead_stats
337                                                         *);
338 #endif
339 #endif                          /* HAVE_SCROLLBARS */
340
341 #ifdef HAVE_MENUBARS
342         /* menubar methods */
343         void (*update_frame_menubars_method) (struct frame *);
344         void (*free_frame_menubars_method) (struct frame *);
345 #endif
346
347 #ifdef HAVE_DIALOGS
348         /* dialog methods */
349          Lisp_Object(*make_dialog_box_internal_method) (struct frame *,
350                                                         Lisp_Object type,
351                                                         Lisp_Object keys);
352 #endif
353 };
354
355 #define CONMETH_TYPE(meths) ((meths)->symbol)
356 #define CONMETH_IMPL_FLAG(meths, f) ((meths)->flags & (f))
357
358 #define CONSOLE_TYPE_NAME(c) ((c)->conmeths->name)
359 #define CONSOLE_TYPE(c) ((c)->conmeths->symbol)
360 #define CONSOLE_IMPL_FLAG(c, f) CONMETH_IMPL_FLAG ((c)->conmeths, (f))
361
362 /******** Accessing / calling a console method *********/
363
364 #define HAS_CONTYPE_METH_P(meth, m) ((meth)->m##_method)
365 #define CONTYPE_METH(meth, m, args) (((meth)->m##_method) args)
366
367 /* Call a void-returning console method, if it exists */
368 #define MAYBE_CONTYPE_METH(meth, m, args) do {                  \
369   struct console_methods *maybe_contype_meth_meth = (meth);     \
370   if (HAS_CONTYPE_METH_P (maybe_contype_meth_meth, m))          \
371     CONTYPE_METH (maybe_contype_meth_meth, m, args);            \
372 } while (0)
373
374 /* Call a console method, if it exists; otherwise return
375    the specified value - meth is multiply evaluated.  */
376 #define CONTYPE_METH_OR_GIVEN(meth, m, args, given)     \
377   (HAS_CONTYPE_METH_P (meth, m) ?                       \
378    CONTYPE_METH (meth, m, args) : (given))
379
380 /* Call an int-returning console method, if it exists; otherwise
381    return 0 */
382 #define MAYBE_INT_CONTYPE_METH(meth, m, args) \
383   CONTYPE_METH_OR_GIVEN (meth, m, args, 0)
384
385 /* Call an Lisp-Object-returning console method, if it exists;
386    otherwise return Qnil */
387 #define MAYBE_LISP_CONTYPE_METH(meth, m, args) \
388   CONTYPE_METH_OR_GIVEN (meth, m, args, Qnil)
389
390 /******** Same functions, operating on a console instead of a
391           struct console_methods ********/
392
393 #define HAS_CONMETH_P(c, m) HAS_CONTYPE_METH_P ((c)->conmeths, m)
394 #define CONMETH(c, m, args) CONTYPE_METH ((c)->conmeths, m, args)
395 #define MAYBE_CONMETH(c, m, args) MAYBE_CONTYPE_METH ((c)->conmeths, m, args)
396 #define CONMETH_OR_GIVEN(c, m, args, given) \
397   CONTYPE_METH_OR_GIVEN((c)->conmeths, m, args, given)
398 #define MAYBE_INT_CONMETH(c, m, args) \
399   MAYBE_INT_CONTYPE_METH ((c)->conmeths, m, args)
400 #define MAYBE_LISP_CONMETH(c, m, args) \
401   MAYBE_LISP_CONTYPE_METH ((c)->conmeths, m, args)
402
403 /******** Defining new console types ********/
404
405 typedef struct console_type_entry console_type_entry;
406 struct console_type_entry {
407         Lisp_Object symbol;
408         struct console_methods *meths;
409 };
410
411 #define DECLARE_CONSOLE_TYPE(type) \
412 extern struct console_methods * type##_console_methods
413
414 #define DEFINE_CONSOLE_TYPE(type) \
415 struct console_methods * type##_console_methods
416
417 #define INITIALIZE_CONSOLE_TYPE(type, obj_name, pred_sym) do {          \
418     type##_console_methods = xnew_and_zero (struct console_methods);    \
419     type##_console_methods->name = obj_name;                            \
420     type##_console_methods->symbol = Q##type;                           \
421     defsymbol_nodump (&type##_console_methods->predicate_symbol, pred_sym);     \
422     add_entry_to_console_type_list (Q##type, type##_console_methods);   \
423     type##_console_methods->image_conversion_list = Qnil;               \
424     staticpro_nodump (&type##_console_methods->image_conversion_list);  \
425     dump_add_root_struct_ptr (&type##_console_methods, &console_methods_description);   \
426 } while (0)
427
428 #define REINITIALIZE_CONSOLE_TYPE(type) do {    \
429     staticpro_nodump (&type##_console_methods->predicate_symbol);       \
430     staticpro_nodump (&type##_console_methods->image_conversion_list);  \
431 } while (0)
432
433 /* Declare that console-type TYPE has method M; used in
434    initialization routines */
435 #define CONSOLE_HAS_METHOD(type, m) \
436   (type##_console_methods->m##_method = type##_##m)
437
438 /* Declare that console-type TYPE inherits method M
439    implementation from console-type FROMTYPE */
440 #define CONSOLE_INHERITS_METHOD(type, fromtype, m) \
441   (type##_console_methods->m##_method = fromtype##_##m)
442
443 /* Define console type implementation flags */
444 #define CONSOLE_IMPLEMENTATION_FLAGS(type, flg) \
445   (type##_console_methods->flags = flg)
446
447 struct console {
448         struct lcrecord_header header;
449
450         /* Description of this console's methods.  */
451         struct console_methods *conmeths;
452
453         /* A structure of auxiliary data specific to the console type.
454            struct x_console is used for X window frames; defined in console-x.h
455            struct tty_console is used to TTY's; defined in console-tty.h */
456         void *console_data;
457
458         /* Character that causes a quit.  Normally C-g.
459            #### Should be possible for this not to be ASCII. */
460         int quit_char;
461
462         /* ----- begin partially-completed console localization of
463            event loop ---- */
464
465         int local_var_flags;
466
467 #define MARKED_SLOT(x) Lisp_Object x
468 #include "conslots.h"
469 #undef MARKED_SLOT
470
471         /* Where to store the next keystroke of the macro.
472            Index into con->kbd_macro_builder. */
473         int kbd_macro_ptr;
474
475         /* The finalized section of the macro starts at kbd_macro_buffer and
476            ends before this.  This is not the same as kbd_macro_pointer, because
477            we advance this to kbd_macro_pointer when a key's command is complete.
478            This way, the keystrokes for "end-kbd-macro" are not included in the
479            macro.  */
480         int kbd_macro_end;
481
482         /* ----- end partially-completed console localization of event loop ---- */
483
484         unsigned int input_enabled:1;
485 };
486
487 DECLARE_LRECORD(console, struct console);
488 #define XCONSOLE(x) XRECORD (x, console, struct console)
489 #define XSETCONSOLE(x, p) XSETRECORD (x, p, console)
490 #define CONSOLEP(x) RECORDP (x, console)
491 #define CHECK_CONSOLE(x) CHECK_RECORD (x, console)
492 #define CONCHECK_CONSOLE(x) CONCHECK_RECORD (x, console)
493
494 #define CHECK_LIVE_CONSOLE(x) do {                      \
495   CHECK_CONSOLE (x);                                    \
496   if (! CONSOLE_LIVE_P (XCONSOLE (x)))                  \
497     dead_wrong_type_argument (Qconsole_live_p, (x));    \
498 } while (0)
499 #define CONCHECK_LIVE_CONSOLE(x) do {                   \
500   CONCHECK_CONSOLE (x);                                 \
501   if (! CONSOLE_LIVE_P (XCONSOLE (x)))                  \
502     x = wrong_type_argument (Qconsole_live_p, (x));     \
503 } while (0)
504
505 #define CONSOLE_TYPE_P(con, type) EQ (CONSOLE_TYPE (con), Q##type)
506
507 #ifdef ERROR_CHECK_TYPECHECK
508 extern_inline struct console *error_check_console_type(struct console *con,
509                                                        Lisp_Object sym);
510 extern_inline struct console *error_check_console_type(struct console *con,
511                                                        Lisp_Object sym)
512 {
513         assert(EQ(CONSOLE_TYPE(con), sym));
514         return con;
515 }
516
517 # define CONSOLE_TYPE_DATA(con, type)                                   \
518         ((struct type##_console *)                                      \
519          ((error_check_console_type((struct console *)con, Q##type))->console_data))
520 # define CONSOLE_DATA(con)      ((struct console *)con)->console_data
521 #else
522 # define CONSOLE_TYPE_DATA(con, type)                           \
523         ((struct type##_console *)(((struct console *)con)->console_data))
524 # define CONSOLE_DATA(con)      ((struct console *)con)->console_data
525 #endif
526
527 #define CHECK_CONSOLE_TYPE(x, type)                                     \
528         do {                                                            \
529                 CHECK_CONSOLE (x);                                      \
530                 if (! CONSOLE_TYPE_P (XCONSOLE (x), type))              \
531                         dead_wrong_type_argument                        \
532                                 (type##_console_methods->               \
533                                  predicate_symbol, x);                  \
534         } while (0)
535 #define CONCHECK_CONSOLE_TYPE(x, type)                                  \
536         do {                                                            \
537                 CONCHECK_CONSOLE (x);                                   \
538                 if (!(CONSOLEP (x) &&                                   \
539                       CONSOLE_TYPE_P (XCONSOLE (x), type)))             \
540                         x = wrong_type_argument                         \
541                                 (type##_console_methods->               \
542                                  predicate_symbol, x);                  \
543         } while (0)
544
545 /* #### These should be in the console-*.h files but there are
546    too many places where the abstraction is broken.  Need to
547    fix. */
548
549 #ifdef HAVE_X_WINDOWS
550 #define CONSOLE_TYPESYM_X_P(typesym) EQ (typesym, Qx)
551 #else
552 #define CONSOLE_TYPESYM_X_P(typesym) 0
553 #endif
554
555 #ifdef HAVE_TTY
556 #define CONSOLE_TYPESYM_TTY_P(typesym) EQ (typesym, Qtty)
557 #else
558 #define CONSOLE_TYPESYM_TTY_P(typesym) 0
559 #endif
560 #define CONSOLE_TYPESYM_STREAM_P(typesym) EQ (typesym, Qstream)
561
562 #define CONSOLE_TYPESYM_WIN_P(typesym) CONSOLE_TYPESYM_X_P (typesym)
563
564 #define CONSOLE_X_P(con) CONSOLE_TYPESYM_X_P (CONSOLE_TYPE (con))
565 #define CHECK_X_CONSOLE(z) CHECK_CONSOLE_TYPE (z, x)
566 #define CONCHECK_X_CONSOLE(z) CONCHECK_CONSOLE_TYPE (z, x)
567
568 #define CONSOLE_TTY_P(con) CONSOLE_TYPESYM_TTY_P (CONSOLE_TYPE (con))
569 #define CHECK_TTY_CONSOLE(z) CHECK_CONSOLE_TYPE (z, tty)
570 #define CONCHECK_TTY_CONSOLE(z) CONCHECK_CONSOLE_TYPE (z, tty)
571
572 #define CONSOLE_STREAM_P(con) CONSOLE_TYPESYM_STREAM_P (CONSOLE_TYPE (con))
573 #define CHECK_STREAM_CONSOLE(z) CHECK_CONSOLE_TYPE (z, stream)
574 #define CONCHECK_STREAM_CONSOLE(z) CONCHECK_CONSOLE_TYPE (z, stream)
575
576 #define CONSOLE_WIN_P(con) CONSOLE_TYPESYM_WIN_P (CONSOLE_TYPE (con))
577
578 EXFUN(Fconsole_disable_input, 1);
579 EXFUN(Fdelete_console, 2);
580 EXFUN(Fselect_console, 1);
581 EXFUN(Fselected_console, 0);
582
583 extern Lisp_Object Qcreate_console_hook, Qdelete_console_hook;
584 extern Lisp_Object Vconsole_defaults, Vconsole_type_list, Vselected_console;
585
586 /* This structure marks which slots in a console have corresponding
587    default values in console_defaults.
588    Each such slot has a nonzero value in this structure.
589    The value has only one nonzero bit.
590
591    When a console has its own local value for a slot,
592    the bit for that slot (found in the same slot in this structure)
593    is turned on in the console's local_var_flags slot.
594
595    If a slot in this structure is zero, then even though there may
596    be a DEFVAR_CONSOLE_LOCAL for the slot, there is no default value for it;
597    and the corresponding slot in console_defaults is not used.  */
598
599 extern struct console console_local_flags;
600
601 int valid_console_type_p(Lisp_Object type);
602
603 #define CONSOLE_LIVE_P(con) (!EQ (CONSOLE_TYPE (con), Qdead))
604
605 #define CONSOLE_NAME(con) ((con)->name)
606 #define CONSOLE_CONNECTION(con) ((con)->connection)
607 #define CONSOLE_CANON_CONNECTION(con) ((con)->canon_connection)
608 #define CONSOLE_FUNCTION_KEY_MAP(con) ((con)->function_key_map)
609 #define CONSOLE_DEVICE_LIST(con) ((con)->device_list)
610 #define CONSOLE_SELECTED_DEVICE(con) ((con)->selected_device)
611 #define CONSOLE_SELECTED_FRAME(con) \
612   DEVICE_SELECTED_FRAME (XDEVICE ((con)->selected_device))
613 #define CONSOLE_LAST_NONMINIBUF_FRAME(con) NON_LVALUE ((con)->last_nonminibuf_frame)
614 #define CONSOLE_QUIT_CHAR(con) ((con)->quit_char)
615
616 #define CDFW_CONSOLE(obj)                               \
617    (WINDOWP  (obj) ? WINDOW_CONSOLE (XWINDOW (obj))     \
618  : (FRAMEP   (obj) ?  FRAME_CONSOLE (XFRAME  (obj))     \
619  : (DEVICEP  (obj) ? DEVICE_CONSOLE (XDEVICE (obj))     \
620  : (CONSOLEP (obj) ? obj                                \
621  : Qnil))))
622
623 #define CONSOLE_LOOP(concons) LIST_LOOP (concons, Vconsole_list)
624 #define CONSOLE_DEVICE_LOOP(devcons, con) \
625   LIST_LOOP (devcons, CONSOLE_DEVICE_LIST (con))
626
627 DECLARE_CONSOLE_TYPE(dead);
628 extern console_type_entry_dynarr *the_console_type_entry_dynarr;
629
630 Lisp_Object create_console(Lisp_Object name, Lisp_Object type,
631                            Lisp_Object connection, Lisp_Object props);
632 void select_console_1(Lisp_Object);
633 struct console *decode_console(Lisp_Object);
634 Lisp_Object make_console(struct console *c);
635 void add_entry_to_console_type_list(Lisp_Object symbol,
636                                     struct console_methods *type);
637 struct console_methods *decode_console_type(Lisp_Object type,
638                                             Error_behavior errb);
639 void delete_console_internal(struct console *con, int force,
640                              int from_kill_emacs, int from_io_error);
641 void io_error_delete_console(Lisp_Object console);
642 void set_console_last_nonminibuf_frame(struct console *con, Lisp_Object frame);
643
644 #endif                          /* INCLUDED_console_h_ */