import -ko -b 1.1.3 XEmacs XEmacs-21_2 r21-2-35
[chise/xemacs-chise.git.1] / src / frame.c
index ccdb8ab..1689076 100644 (file)
@@ -121,8 +121,6 @@ static struct display_line title_string_display_line;
    the dynamic allocation time adds up. */
 static Emchar_dynarr *title_string_emchar_dynarr;
 
-EXFUN (Fset_frame_properties, 2);
-
 \f
 static Lisp_Object
 mark_frame (Lisp_Object obj)
@@ -132,8 +130,6 @@ mark_frame (Lisp_Object obj)
 #define MARKED_SLOT(x) mark_object (f->x)
 #include "frameslots.h"
 
-  mark_subwindow_cachels (f->subwindow_cachels);
-
   if (FRAME_LIVE_P (f)) /* device is nil for a dead frame */
     MAYBE_FRAMEMETH (f, mark_frame, (f));
 
@@ -210,12 +206,14 @@ allocate_frame_core (Lisp_Object device)
   f->last_nonminibuf_window = root_window;
 
   /* cache of subwindows visible on frame */
-  f->subwindow_cachels    = Dynarr_new (subwindow_cachel);
+  f->subwindow_instance_cache    = make_weak_list (WEAK_LIST_SIMPLE);
 
   /* associated exposure ignore list */
   f->subwindow_exposures = 0;
   f->subwindow_exposures_tail = 0;
 
+  FRAME_SET_PAGENUMBER (f, 1);
+
   /* Choose a buffer for the frame's root window.  */
   XWINDOW (root_window)->buffer = Qt;
   {
@@ -226,7 +224,7 @@ allocate_frame_core (Lisp_Object device)
        a space), try to find another one.  */
     if (string_char (XSTRING (Fbuffer_name (buf)), 0) == ' ')
       buf = Fother_buffer (buf, Qnil, Qnil);
-    Fset_window_buffer (root_window, buf);
+    Fset_window_buffer (root_window, buf, Qnil);
   }
 
   return f;
@@ -249,7 +247,7 @@ setup_normal_frame (struct frame *f)
   f->has_minibuffer = 1;
 
   XWINDOW (mini_window)->buffer = Qt;
-  Fset_window_buffer (mini_window, Vminibuffer_zero);
+  Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
 }
 
 /* Make a frame using a separate minibuffer window on another frame.
@@ -270,7 +268,9 @@ setup_frame_without_minibuffer (struct frame *f, Lisp_Object mini_window)
              FRAME_CONSOLE (XFRAME (XWINDOW (mini_window)->frame))))
     error ("frame and minibuffer must be on the same console");
 
-  if (NILP (mini_window))
+  /* Do not create a default minibuffer frame on printer devices.  */
+  if (NILP (mini_window)
+      && DEVICE_DISPLAY_P (XDEVICE (FRAME_DEVICE (f))))
     {
       struct console *con = XCONSOLE (FRAME_CONSOLE (f));
       /* Use default-minibuffer-frame if possible.  */
@@ -285,8 +285,13 @@ setup_frame_without_minibuffer (struct frame *f, Lisp_Object mini_window)
     }
 
   /* Install the chosen minibuffer window, with proper buffer.  */
-  store_minibuf_frame_prop (f, mini_window);
-  Fset_window_buffer (mini_window, Vminibuffer_zero);
+  if (!NILP (mini_window))
+    {
+      store_minibuf_frame_prop (f, mini_window);
+      Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
+    }
+  else
+    f->minibuffer_window = Qnil;
 }
 
 /* Make a frame containing only a minibuffer window.  */
@@ -316,7 +321,7 @@ setup_minibuffer_frame (struct frame *f)
 
   /* Put the proper buffer in that window.  */
 
-  Fset_window_buffer (mini_window, Vminibuffer_zero);
+  Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
 }
 
 static Lisp_Object
@@ -380,7 +385,7 @@ See `set-frame-properties', `default-x-frame-plist', and
   else
     name = build_string ("emacs");
 
-  if (!NILP (Fstring_match (make_string ((CONST Bufbyte *) "\\.", 2), name,
+  if (!NILP (Fstring_match (make_string ((const Bufbyte *) "\\.", 2), name,
                            Qnil, Qnil)))
     signal_simple_error (". not allowed in frame names", name);
 
@@ -466,20 +471,14 @@ See `set-frame-properties', `default-x-frame-plist', and
 #endif
       reset_face_cachels (XWINDOW (FRAME_SELECTED_WINDOW (f)));
       reset_glyph_cachels (XWINDOW (FRAME_SELECTED_WINDOW (f)));
-      reset_subwindow_cachels (f);
-      change_frame_size (f, f->height, f->width, 0);
 
+      change_frame_size (f, f->height, f->width, 0);
     }
 
   MAYBE_FRAMEMETH (f, init_frame_2, (f, props));
   Fset_frame_properties (frame, props);
   MAYBE_FRAMEMETH (f, init_frame_3, (f));
 
-  /* now initialise the gutters, this won't change the frame size
-     so is ok here. */
-  if (!DEVICE_STREAM_P (d))
-    init_frame_gutters (f);
-
   /* Hallelujah, praise the lord. */
   f->init_finished = 1;
 
@@ -505,6 +504,18 @@ See `set-frame-properties', `default-x-frame-plist', and
   MAYBE_FRAMEMETH (f, after_init_frame, (f, first_frame_on_device,
                                         first_frame_on_console));
 
+  if (!DEVICE_STREAM_P (d))
+    {
+      /* Now initialise the gutters. This won't change the frame size,
+         but is needed as input to the layout that change_frame_size
+         will eventually do. Unfortunately gutter sizing code relies
+         on the frame in question being visible so we can't do this
+         earlier. */
+      init_frame_gutters (f);
+
+      change_frame_size (f, f->height, f->width, 0);
+    }
+
   if (first_frame_on_device)
     {
       if (first_frame_on_console)
@@ -905,13 +916,13 @@ set_frame_selected_window (struct frame *f, Lisp_Object window)
   f->selected_window = window;
   if (!MINI_WINDOW_P (XWINDOW (window)) || FRAME_MINIBUF_ONLY_P (f))
     {
-#ifdef HAVE_TOOLBARS
       if (!EQ (f->last_nonminibuf_window, window))
        {
+#ifdef HAVE_TOOLBARS
          MARK_TOOLBAR_CHANGED;
+#endif
          MARK_GUTTER_CHANGED;
        }
-#endif
       f->last_nonminibuf_window = window;
     }
 }
@@ -1322,7 +1333,9 @@ delete_frame_internal (struct frame *f, int force,
   console = DEVICE_CONSOLE (d);
   con = XCONSOLE (console);
 
-  if (!called_from_delete_device)
+  if (!called_from_delete_device &&
+      !(MAYBE_INT_DEVMETH (d, device_implementation_flags, ())
+       & XDEVIMPF_FRAMELESS_OK))
     {
       /* If we're deleting the only non-minibuffer frame on the
         device, delete the device. */
@@ -1508,7 +1521,7 @@ delete_frame_internal (struct frame *f, int force,
                    next_frame_internal (frame, Qt, device,
                                         called_from_delete_device);
                if (NILP (next_f) || EQ (next_f, frame))
-                 ;
+                 set_device_selected_frame (d, Qnil);
                else
                  set_device_selected_frame (d, next_f);
            }
@@ -1523,7 +1536,7 @@ delete_frame_internal (struct frame *f, int force,
     {
       struct frame *sel_frame = selected_frame ();
       Fset_window_buffer (sel_frame->minibuffer_window,
-                         XWINDOW (minibuf_window)->buffer);
+                         XWINDOW (minibuf_window)->buffer, Qt);
       minibuf_window = sel_frame->minibuffer_window;
 
       /* If the dying minibuffer window was selected,
@@ -1544,6 +1557,12 @@ delete_frame_internal (struct frame *f, int force,
   free_frame_toolbars (f);
 #endif
   free_frame_gutters (f);
+  /* Unfortunately deleting the frame will also delete the parent of
+     all of the subwindow instances current on the frame. I think this
+     can lead to bad things when trying to finalize the
+     instances. Thus we loop over the instance cache calling the
+     finalize method for each instance. */
+  free_frame_subwindow_instance_cache (f);
 
   /* This must be done before the window and window_mirror structures
      are freed.  The scrollbar information is attached to them. */
@@ -1555,11 +1574,7 @@ delete_frame_internal (struct frame *f, int force,
   f->root_window = Qnil;
 
   /* clear out the cached glyph information */
-  if (f->subwindow_cachels)
-    {
-      Dynarr_free (f->subwindow_cachels);
-      f->subwindow_cachels = 0;
-    }
+  f->subwindow_instance_cache = Qnil;
 
   /* Remove the frame now from the list.  This way, any events generated
      on this frame by the maneuvers below will disperse themselves. */
@@ -1929,7 +1944,7 @@ you may do so.
   if (EQ (f->minibuffer_window, minibuf_window))
     {
       Fset_window_buffer (sel_frame->minibuffer_window,
-                         XWINDOW (minibuf_window)->buffer);
+                         XWINDOW (minibuf_window)->buffer, Qt);
       minibuf_window = sel_frame->minibuffer_window;
     }
 
@@ -1955,7 +1970,7 @@ If omitted, FRAME defaults to the currently selected frame.
   if (EQ (f->minibuffer_window, minibuf_window))
     {
       Fset_window_buffer (sel_frame->minibuffer_window,
-                         XWINDOW (minibuf_window)->buffer);
+                         XWINDOW (minibuf_window)->buffer, Qt);
       minibuf_window = sel_frame->minibuffer_window;
     }
 
@@ -2087,6 +2102,31 @@ doesn't support multiple overlapping frames, this function does nothing.
 
 /* Ben thinks there is no need for `redirect-frame-focus' or `frame-focus',
    crockish FSFmacs functions.  See summary on focus in event-stream.c. */
+\f
+DEFUN ("print-job-page-number", Fprint_job_page_number, 1, 1, 0, /*
+Return current page number for the print job FRAME.
+*/
+       (frame))
+{
+  CHECK_PRINTER_FRAME (frame);
+  return make_int (FRAME_PAGENUMBER (XFRAME (frame)));
+}
+
+DEFUN ("print-job-eject-page", Fprint_job_eject_page, 1, 1, 0, /*
+Eject page in the print job FRAME.
+*/
+       (frame))
+{
+  struct frame *f;
+
+  CHECK_PRINTER_FRAME (frame);
+  f = XFRAME (frame);
+  FRAMEMETH (f, eject_page, (f));
+  FRAME_SET_PAGENUMBER (f, 1 + FRAME_PAGENUMBER (f));
+  f->clear = 1;
+
+  return Qnil;
+}
 
 \f
 /***************************************************************************/
@@ -2142,7 +2182,7 @@ dissect_as_face_setting (Lisp_Object sym, Lisp_Object *face_out,
                         Lisp_Object *face_prop_out)
 {
   Lisp_Object list = Vbuilt_in_face_specifiers;
-  struct Lisp_String *s;
+  Lisp_String *s;
 
   if (!SYMBOLP (sym))
     return 0;
@@ -2152,7 +2192,7 @@ dissect_as_face_setting (Lisp_Object sym, Lisp_Object *face_out,
   while (!NILP (list))
     {
       Lisp_Object prop = Fcar (list);
-      struct Lisp_String *prop_name;
+      Lisp_String *prop_name;
 
       if (!SYMBOLP (prop))
        continue;
@@ -2230,8 +2270,9 @@ The following symbols etc. have predefined meanings:
 
  minibuffer    Gives the minibuffer behavior for this frame.  Either
                t (frame has its own minibuffer), `only' (frame is
-               a minibuffer-only frame), or a window (frame uses that
-               window, which is on another frame, as the minibuffer).
+               a minibuffer-only frame), `none' (frame has no minibuffer)
+               or a window (frame uses that window, which is on another
+               frame, as the minibuffer).
 
  unsplittable  If non-nil, frame cannot be split by `display-buffer'.
 
@@ -2245,7 +2286,13 @@ The following symbols etc. have predefined meanings:
  left-toolbar-visible-p, right-toolbar-visible-p, toolbar-buttons-captioned-p,
  top-toolbar-border-width, bottom-toolbar-border-width,
  left-toolbar-border-width, right-toolbar-border-width,
- modeline-shadow-thickness, has-modeline-p
+ modeline-shadow-thickness, has-modeline-p,
+ default-gutter, top-gutter, bottom-gutter, left-gutter, right-gutter,
+ default-gutter-height, default-gutter-width, top-gutter-height,
+ bottom-gutter-height, left-gutter-width, right-gutter-width,
+ default-gutter-visible-p, top-gutter-visible-p, bottom-gutter-visible-p,
+ left-gutter-visible-p, right-gutter-visible-p, top-gutter-border-width,
+ bottom-gutter-border-width, left-gutter-border-width, right-gutter-border-width,
                [Giving the name of any built-in specifier variable is
                equivalent to calling `set-specifier' on the specifier,
                with a locale of FRAME.  Giving the name to `frame-property'
@@ -2854,9 +2901,9 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth)
   {
     int adjustment, trunc_width, cont_width;
 
-    trunc_width = glyph_width (Vtruncation_glyph, 
+    trunc_width = glyph_width (Vtruncation_glyph,
                               FRAME_SELECTED_WINDOW (f));
-    cont_width = glyph_width (Vcontinuation_glyph, 
+    cont_width = glyph_width (Vcontinuation_glyph,
                              FRAME_SELECTED_WINDOW (f));
     adjustment = max (trunc_width, cont_width);
     adjustment = max (adjustment, font_width);
@@ -2870,7 +2917,14 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth)
 
   if (new_pixheight)
     {
-      XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top = FRAME_TOP_BORDER_END (f);
+      /* Adjust for gutters here so that we always get set
+         properly. */
+      new_pixheight -= 
+       (FRAME_TOP_GUTTER_BOUNDS (f)
+        + FRAME_BOTTOM_GUTTER_BOUNDS (f));
+
+      XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top 
+       = FRAME_TOP_BORDER_END (f) + FRAME_TOP_GUTTER_BOUNDS (f);
 
       if (FRAME_HAS_MINIBUF_P (f)
          && ! FRAME_MINIBUF_ONLY_P (f))
@@ -2896,7 +2950,10 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth)
                                new_pixheight - minibuf_height, 0);
 
          XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top =
-           new_pixheight - minibuf_height + FRAME_TOP_BORDER_END (f);
+           FRAME_TOP_BORDER_END (f) +
+           FRAME_TOP_GUTTER_BOUNDS (f) + 
+           FRAME_BOTTOM_GUTTER_BOUNDS (f) +
+           new_pixheight - minibuf_height;
 
          set_window_pixheight (FRAME_MINIBUF_WINDOW (f), minibuf_height, 0);
        }
@@ -2911,13 +2968,20 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth)
 
   if (new_pixwidth)
     {
-      XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left = FRAME_LEFT_BORDER_END (f);
+      /* Adjust for gutters here so that we always get set
+         properly. */
+      new_pixwidth -= 
+       (FRAME_LEFT_GUTTER_BOUNDS (f)
+        + FRAME_RIGHT_GUTTER_BOUNDS (f));
+      
+      XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left = 
+       FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f);
       set_window_pixwidth (FRAME_ROOT_WINDOW (f), new_pixwidth, 0);
 
       if (FRAME_HAS_MINIBUF_P (f))
        {
          XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_left =
-           FRAME_LEFT_BORDER_END (f);
+           FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f);
          set_window_pixwidth (FRAME_MINIBUF_WINDOW (f), new_pixwidth, 0);
        }
 
@@ -2936,6 +3000,7 @@ change_frame_size_1 (struct frame *f, int newheight, int newwidth)
     }
 
   MARK_FRAME_TOOLBARS_CHANGED (f);
+  MARK_FRAME_GUTTERS_CHANGED (f);
   MARK_FRAME_CHANGED (f);
   f->echo_area_garbaged = 1;
 }
@@ -3118,6 +3183,8 @@ init_frame (void)
 void
 syms_of_frame (void)
 {
+  INIT_LRECORD_IMPLEMENTATION (frame);
+
   defsymbol (&Qdelete_frame_hook, "delete-frame-hook");
   defsymbol (&Qselect_frame_hook, "select-frame-hook");
   defsymbol (&Qdeselect_frame_hook, "deselect-frame-hook");
@@ -3228,6 +3295,8 @@ syms_of_frame (void)
   DEFSUBR (Fset_frame_size);
   DEFSUBR (Fset_frame_position);
   DEFSUBR (Fset_frame_pointer);
+  DEFSUBR (Fprint_job_page_number);
+  DEFSUBR (Fprint_job_eject_page);
 }
 
 void
@@ -3341,11 +3410,17 @@ visible frames.
   Vsynchronize_minibuffers = Qnil;
 
   DEFVAR_LISP ("frame-title-format", &Vframe_title_format /*
-Controls the title of the X window corresponding to the selected frame.
+Controls the title of the window-system window of the selected frame.
 This is the same format as `modeline-format' with the exception that
 %- is ignored.
 */ );
+/* #### I would change this unilaterally but for the wrath of the Kyles
+of the world. */
+#ifdef WIN32_NATIVE
+  Vframe_title_format = build_string ("%b - XEmacs");
+#else
   Vframe_title_format = build_string ("%S: %b");
+#endif
 
   DEFVAR_LISP ("frame-icon-title-format", &Vframe_icon_title_format /*
 Controls the title of the icon corresponding to the selected frame.
@@ -3355,8 +3430,9 @@ See also the variable `frame-title-format'.
 
   DEFVAR_LISP ("default-frame-name", &Vdefault_frame_name /*
 The default name to assign to newly-created frames.
-This can be overridden by arguments to `make-frame'.
-This must be a string.
+This can be overridden by arguments to `make-frame'.  This must be a string.
+This is used primarily for picking up X resources, and is *not* the title
+of the frame. (See `frame-title-format'.)
 */ );
 #ifndef INFODOCK
   Vdefault_frame_name = build_string ("emacs");