update.
[chise/xemacs-chise.git.1] / src / device.c
index e96ff39..399d61d 100644 (file)
@@ -1,4 +1,4 @@
- /* Generic device functions.
+/* Generic device functions.
    Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
    Copyright (C) 1994, 1995 Free Software Foundation, Inc.
    Copyright (C) 1995, 1996 Ben Wing
@@ -37,11 +37,14 @@ Boston, MA 02111-1307, USA.  */
 #include "frame.h"
 #include "keymap.h"
 #include "redisplay.h"
-#include "scrollbar.h"
 #include "specifier.h"
 #include "sysdep.h"
 #include "window.h"
 
+#ifdef HAVE_SCROLLBARS
+#include "scrollbar.h"
+#endif
+
 #include "syssignal.h"
 
 /* Vdefault_device is the firstly-created non-stream device that's still
@@ -65,47 +68,45 @@ Lisp_Object
   Qfont_menubar, Qfont_dialog, Qsize_cursor, Qsize_scrollbar,
   Qsize_menu, Qsize_toolbar, Qsize_toolbar_button,
   Qsize_toolbar_border, Qsize_icon, Qsize_icon_small, Qsize_device,
-  Qsize_workspace, Qsize_device_mm, Qdevice_dpi, Qnum_bit_planes,
-  Qnum_color_cells, Qmouse_buttons, Qswap_buttons, Qshow_sounds,
-  Qslow_device, Qsecurity;
+  Qsize_workspace, Qoffset_workspace, Qsize_device_mm, Qdevice_dpi,
+  Qnum_bit_planes, Qnum_color_cells, Qmouse_buttons, Qswap_buttons,
+  Qshow_sounds, Qslow_device, Qsecurity;
 
 Lisp_Object Qdevicep, Qdevice_live_p;
-Lisp_Object Qdelete_device;
 Lisp_Object Qcreate_device_hook;
 Lisp_Object Qdelete_device_hook;
-
 Lisp_Object Vdevice_class_list;
 
 \f
 static Lisp_Object
-mark_device (Lisp_Object obj, void (*markobj) (Lisp_Object))
+mark_device (Lisp_Object obj)
 {
   struct device *d = XDEVICE (obj);
 
-  ((markobj) (d->name));
-  ((markobj) (d->connection));
-  ((markobj) (d->canon_connection));
-  ((markobj) (d->console));
-  ((markobj) (d->_selected_frame));
-  ((markobj) (d->frame_with_focus_real));
-  ((markobj) (d->frame_with_focus_for_hooks));
-  ((markobj) (d->frame_that_ought_to_have_focus));
-  ((markobj) (d->device_class));
-  ((markobj) (d->user_defined_tags));
-  ((markobj) (d->pixel_to_glyph_cache.obj1));
-  ((markobj) (d->pixel_to_glyph_cache.obj2));
-
-  ((markobj) (d->color_instance_cache));
-  ((markobj) (d->font_instance_cache));
+  mark_object (d->name);
+  mark_object (d->connection);
+  mark_object (d->canon_connection);
+  mark_object (d->console);
+  mark_object (d->selected_frame);
+  mark_object (d->frame_with_focus_real);
+  mark_object (d->frame_with_focus_for_hooks);
+  mark_object (d->frame_that_ought_to_have_focus);
+  mark_object (d->device_class);
+  mark_object (d->user_defined_tags);
+  mark_object (d->pixel_to_glyph_cache.obj1);
+  mark_object (d->pixel_to_glyph_cache.obj2);
+
+  mark_object (d->color_instance_cache);
+  mark_object (d->font_instance_cache);
 #ifdef MULE
-  ((markobj) (d->charset_font_cache));
+  mark_object (d->charset_font_cache);
 #endif
-  ((markobj) (d->image_instance_cache));
+  mark_object (d->image_instance_cache);
 
   if (d->devmeths)
     {
-      ((markobj) (d->devmeths->symbol));
-      MAYBE_DEVMETH (d, mark_device, (d, markobj));
+      mark_object (d->devmeths->symbol);
+      MAYBE_DEVMETH (d, mark_device, (d));
     }
 
   return (d->frame_list);
@@ -124,7 +125,7 @@ print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
   sprintf (buf, "#<%s-device", !DEVICE_LIVE_P (d) ? "dead" :
           DEVICE_TYPE_NAME (d));
   write_c_string (buf, printcharfun);
-  if (DEVICE_LIVE_P (d))
+  if (DEVICE_LIVE_P (d) && !NILP (DEVICE_CONNECTION (d)))
     {
       write_c_string (" on ", printcharfun);
       print_internal (DEVICE_CONNECTION (d), printcharfun, 1);
@@ -134,7 +135,7 @@ print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 }
 
 DEFINE_LRECORD_IMPLEMENTATION ("device", device,
-                              mark_device, print_device, 0, 0, 0,
+                              mark_device, print_device, 0, 0, 0, 0,
                               struct device);
 \f
 int
@@ -164,7 +165,7 @@ static struct device *
 allocate_device (Lisp_Object console)
 {
   Lisp_Object device;
-  struct device *d = alloc_lcrecord_type (struct device, lrecord_device);
+  struct device *d = alloc_lcrecord_type (struct device, &lrecord_device);
   struct gcpro gcpro1;
 
   zero_lcrecord (d);
@@ -177,7 +178,7 @@ allocate_device (Lisp_Object console)
   d->connection = Qnil;
   d->canon_connection = Qnil;
   d->frame_list = Qnil;
-  d->_selected_frame = Qnil;
+  d->selected_frame = Qnil;
   d->frame_with_focus_real = Qnil;
   d->frame_with_focus_for_hooks = Qnil;
   d->frame_that_ought_to_have_focus = Qnil;
@@ -189,22 +190,22 @@ allocate_device (Lisp_Object console)
   d->infd = d->outfd = -1;
 
   /* #### is 20 reasonable? */
-  d->color_instance_cache = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
-                                                HASHTABLE_EQUAL);
-  d->font_instance_cache = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
-                                               HASHTABLE_EQUAL);
+  d->color_instance_cache =
+    make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQUAL);
+  d->font_instance_cache =
+    make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQUAL);
 #ifdef MULE
   /* Note that the following table is bi-level. */
-  d->charset_font_cache = make_lisp_hashtable (20, HASHTABLE_NONWEAK,
-                                              HASHTABLE_EQ);
+  d->charset_font_cache =
+    make_lisp_hash_table (20, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
 #endif
   /*
      Note that the image instance cache is actually bi-level.
      See device.h.  We use a low number here because most of the
-     time there aren't very many diferent masks that will be used.
+     time there aren't very many different masks that will be used.
      */
-  d->image_instance_cache = make_lisp_hashtable (5, HASHTABLE_NONWEAK,
-                                                HASHTABLE_EQ);
+  d->image_instance_cache =
+    make_lisp_hash_table (5, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
 
   UNGCPRO;
   return d;
@@ -216,7 +217,7 @@ decode_device (Lisp_Object device)
   if (NILP (device))
     device = Fselected_device (Qnil);
   /* quietly accept frames for the device arg */
-  if (FRAMEP (device))
+  else if (FRAMEP (device))
     device = FRAME_DEVICE (decode_frame (device));
   CHECK_LIVE_DEVICE (device);
   return XDEVICE (device);
@@ -226,9 +227,9 @@ DEFUN ("dfw-device", Fdfw_device, 1, 1, 0, /*
 Given a device, frame, or window, return the associated device.
 Return nil otherwise.
 */
-       (obj))
+       (object))
 {
-  return DFW_DEVICE (obj);
+  return DFW_DEVICE (object);
 }
 
 \f
@@ -287,7 +288,7 @@ set_device_selected_frame (struct device *d, Lisp_Object frame)
 {
   if (!NILP (frame) && !FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
     set_console_last_nonminibuf_frame (XCONSOLE (DEVICE_CONSOLE (d)), frame);
-  d->_selected_frame = frame;
+  d->selected_frame = frame;
 }
 
 DEFUN ("set-device-selected-frame", Fset_device_selected_frame, 2, 2, 0, /*
@@ -385,16 +386,24 @@ static Lisp_Object
 semi_canonicalize_device_connection (struct console_methods *meths,
                                     Lisp_Object name, Error_behavior errb)
 {
-  return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_device_connection,
-                               (name, errb), name);
+  if (HAS_CONTYPE_METH_P (meths, semi_canonicalize_device_connection))
+    return CONTYPE_METH (meths, semi_canonicalize_device_connection,
+                        (name, errb));
+  else
+    return CONTYPE_METH_OR_GIVEN (meths, canonicalize_device_connection,
+                                 (name, errb), name);
 }
 
 static Lisp_Object
 canonicalize_device_connection (struct console_methods *meths,
                                Lisp_Object name, Error_behavior errb)
 {
-  return CONTYPE_METH_OR_GIVEN (meths, canonicalize_device_connection,
-                               (name, errb), name);
+  if (HAS_CONTYPE_METH_P (meths, canonicalize_device_connection))
+    return CONTYPE_METH (meths, canonicalize_device_connection,
+                        (name, errb));
+  else
+    return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_device_connection,
+                                 (name, errb), name);
 }
 
 static Lisp_Object
@@ -540,6 +549,9 @@ have no effect.
      device-independence violations occur in faces.el. */
   int first_x_device = NILP (Vdefault_x_device) && EQ (type, Qx);
 #endif
+#ifdef HAVE_GTK
+  int first_gtk_device = NILP (Vdefault_gtk_device) && EQ (type, Qgtk);
+#endif
 
   GCPRO3 (device, console, name);
 
@@ -589,6 +601,10 @@ have no effect.
   if (first_x_device)
     init_global_resources (d);
 #endif
+#ifdef HAVE_GTK
+  if (first_gtk_device)
+    init_global_resources (d);
+#endif
   init_device_resources (d);
 
   MAYBE_DEVMETH (d, finish_init_device, (d, props));
@@ -749,7 +765,8 @@ delete_device_internal (struct device *d, int force,
 
     /* #### This should probably be a device method but it is time for
        19.14 to go out the door. */
-#ifdef HAVE_X_WINDOWS
+    /* #### BILL!!! Should this deal with HAVE_MSWINDOWS as well? */
+#if defined (HAVE_X_WINDOWS) || defined (HAVE_GTK)
     /* Next delete all frames which have the popup property to avoid
        deleting a child after its parent. */
     DEVICE_FRAME_LOOP (frmcons, d)
@@ -817,6 +834,9 @@ delete_device_internal (struct device *d, int force,
 void
 io_error_delete_device (Lisp_Object device)
 {
+  /* Note: it's the console that should get deleted, but
+     delete_device_internal() contains a hack that also deletes the
+     console when called from this function.  */
   delete_device_internal (XDEVICE (device), 1, 0, 1);
 }
 
@@ -877,7 +897,9 @@ behavior cannot necessarily be determined automatically.
          recompute_all_cached_specifiers_in_frame (f);
          MARK_FRAME_FACES_CHANGED (f);
          MARK_FRAME_GLYPHS_CHANGED (f);
+         MARK_FRAME_SUBWINDOWS_CHANGED (f);
          MARK_FRAME_TOOLBARS_CHANGED (f);
+         MARK_FRAME_GUTTERS_CHANGED (f);
          f->menubar_changed = 1;
        }
     }
@@ -906,12 +928,21 @@ Return the output baud rate of DEVICE.
   return make_int (DEVICE_BAUD_RATE (decode_device (device)));
 }
 
+DEFUN ("device-printer-p", Fdevice_printer_p, 0, 1, 0, /*
+Return t if DEVICE is a printer, nil if it is a display. DEVICE defaults
+to selected device if omitted, and must be live if specified.
+*/
+       (device))
+{
+  return DEVICE_PRINTER_P (decode_device (device)) ? Qt : Qnil;
+}
+
 DEFUN ("device-system-metric", Fdevice_system_metric, 1, 3, 0, /*
 Get a metric for DEVICE as provided by the system.
 
 METRIC must be a symbol specifying requested metric.  Note that the metrics
 returned are these provided by the system internally, not read from resources,
-so obtained from the most internal level. 
+so obtained from the most internal level.
 
 If a metric is not provided by the system, then DEFAULT is returned.
 
@@ -920,14 +951,14 @@ When DEVICE is nil, selected device is assumed
 Metrics, by group, are:
 
 COLORS.  Colors are returned as valid color instantiators.  No other assumption
-on the returned valie should be made (i.e. it can be a string on one system but
+on the returned value should be made (i.e. it can be a string on one system but
 a color instance on another).  For colors, returned value is a cons of
 foreground and background colors.  Note that if the system provides only one
 color of the pair, the second one may be nil.
 
 color-default         Standard window text foreground and background.
-color-select          Selection highligh text and backgroun colors.
-color-balloon         Ballon popup text and background colors.
+color-select          Selection highlight text and background colors.
+color-balloon         Balloon popup text and background colors.
 color-3d-face         3-D object (button, modeline) text and surface colors.
 color-3d-light        Fore and back colors for 3-D edges facing light source.
 color-3d-dark         Fore and back colors for 3-D edges facing away from
@@ -951,7 +982,7 @@ font-dialog           Dialog boxes font
 
 GEOMETRY. These metrics are returned as conses of (X . Y).  As with colors,
 either car or cdr of the cons may be nil if the system does not provide one
-of corresponding dimensions.
+of the corresponding dimensions.
 
 size-cursor           Mouse cursor size.
 size-scrollbar        Scrollbars (WIDTH . HEIGHT)
@@ -961,21 +992,24 @@ size-toolbar-button   Toolbar button size.
 size-toolbar-border   Toolbar border width and height.
 size-icon             Icon dimensions.
 size-icon-small       Small icon dimensions.
-size-device           Device screen size in pixels.
-size-workspace        Workspace size in pixels. This can be less than the
-                      above if window manager has decorations which
-                      effectively shrink the area remaining for application
-                      windows.
+size-device           Device screen or paper size in pixels.
+size-workspace        Workspace size in pixels. This can be less than or
+                      equal to the above. For displays, this is the area
+                      available to applications less window manager
+                      decorations. For printers, this is the size of
+                      printable area.
+offset-workspace      Offset of workspace area from the top left corner
+                      of screen or paper, in pixels.
 size-device-mm        Device screen size in millimeters.
 device-dpi            Device resolution, in dots per inch.
-num-bit-planes        Integer, number of deivce bit planes.
+num-bit-planes        Integer, number of device bit planes.
 num-color-cells       Integer, number of device color cells.
 
 FEATURES.  This group reports various device features.  If a feature is
 present, integer 1 (one) is returned, if it is not present, then integer
 0 (zero) is returned.  If the system is unaware of the feature, then
 DEFAULT is returned.
-                
+
 mouse-buttons         Integer, number of mouse buttons, or zero if no mouse.
 swap-buttons          Non-zero if left and right mouse buttons are swapped.
 show-sounds           User preference for visual over audible bell.
@@ -1022,6 +1056,7 @@ security              Non-zero if user environment is secure.
   FROB (size_icon_small);
   FROB (size_device);
   FROB (size_workspace);
+  FROB (offset_workspace);
   FROB (size_device_mm);
   FROB (device_dpi);
   FROB (num_bit_planes);
@@ -1084,6 +1119,7 @@ DEVICE defaults to selected device when omitted.
   FROB (size_icon_small);
   FROB (size_device);
   FROB (size_workspace);
+  FROB (offset_workspace);
   FROB (size_device_mm);
   FROB (device_dpi);
   FROB (num_bit_planes);
@@ -1139,8 +1175,7 @@ window_system_pixelated_geometry (Lisp_Object domain)
   Lisp_Object winsy = domain_device_type (domain);
   struct console_methods *meth = decode_console_type (winsy, ERROR_ME_NOT);
   assert (meth);
-  return (MAYBE_INT_CONTYPE_METH (meth, device_implementation_flags, ())
-         & XDEVIMPF_PIXEL_GEOMETRY);
+  return CONMETH_IMPL_FLAG (meth, XDEVIMPF_PIXEL_GEOMETRY);
 }
 
 DEFUN ("domain-device-type", Fdomain_device_type, 0, 1, 0, /*
@@ -1172,12 +1207,12 @@ handle_asynch_device_change (void)
   /* reset the flag to 0 unless another notification occurred while
      we were processing this one.  Block SIGWINCH during this
      check to prevent a possible race condition. */
-#ifndef WINDOWSNT
+#ifdef SIGWINCH
   EMACS_BLOCK_SIGNAL (SIGWINCH);
 #endif
   if (old_asynch_device_change_pending == asynch_device_change_pending)
     asynch_device_change_pending = 0;
-#ifndef WINDOWSNT
+#ifdef SIGWINCH
   EMACS_UNBLOCK_SIGNAL (SIGWINCH);
 #endif
 }
@@ -1217,6 +1252,8 @@ call_critical_lisp_code (struct device *d, Lisp_Object function,
 void
 syms_of_device (void)
 {
+  INIT_LRECORD_IMPLEMENTATION (device);
+
   DEFSUBR (Fvalid_device_class_p);
   DEFSUBR (Fdevice_class_list);
 
@@ -1241,10 +1278,10 @@ syms_of_device (void)
   DEFSUBR (Fset_device_baud_rate);
   DEFSUBR (Fdevice_baud_rate);
   DEFSUBR (Fdomain_device_type);
+  DEFSUBR (Fdevice_printer_p);
 
   defsymbol (&Qdevicep, "devicep");
   defsymbol (&Qdevice_live_p, "device-live-p");
-  defsymbol (&Qdelete_device, "delete-device");
 
   defsymbol (&Qcreate_device_hook, "create-device-hook");
   defsymbol (&Qdelete_device_hook, "delete-device-hook");
@@ -1281,6 +1318,7 @@ syms_of_device (void)
   defsymbol (&Qsize_icon_small, "size-icon-small");
   defsymbol (&Qsize_device, "size-device");
   defsymbol (&Qsize_workspace, "size-workspace");
+  defsymbol (&Qoffset_workspace, "offset-workspace");
   defsymbol (&Qsize_device_mm, "size-device-mm");
   defsymbol (&Qnum_bit_planes, "num-bit-planes");
   defsymbol (&Qnum_color_cells, "num-color-cells");
@@ -1293,8 +1331,18 @@ syms_of_device (void)
 }
 
 void
+reinit_vars_of_device (void)
+{
+  staticpro_nodump (&Vdefault_device);
+  Vdefault_device = Qnil;
+  asynch_device_change_pending = 0;
+}
+
+void
 vars_of_device (void)
 {
+  reinit_vars_of_device ();
+
   DEFVAR_LISP ("create-device-hook", &Vcreate_device_hook /*
 Function or functions to call when a device is created.
 One argument, the newly-created device.
@@ -1310,11 +1358,6 @@ One argument, the to-be-deleted device.
 */ );
   Vdelete_device_hook = Qnil;
 
-  staticpro (&Vdefault_device);
-  Vdefault_device = Qnil;
-
-  asynch_device_change_pending = 0;
-
   Vdevice_class_list = list3 (Qcolor, Qgrayscale, Qmono);
   staticpro (&Vdevice_class_list);