XEmacs 21.2.28 "Hermes".
[chise/xemacs-chise.git.1] / src / window.c
index a63fe35..3a86d72 100644 (file)
@@ -710,7 +710,7 @@ int
 window_truncation_on (struct window *w)
 {
     /* Minibuffer windows are never truncated.
-       ### is this the right way ? */
+       #### is this the right way ? */
   if (MINI_WINDOW_P (w))
     return 0;
 
@@ -1148,7 +1148,7 @@ be used.  Otherwise, the selected frame is used.
   return FRAME_MINIBUF_WINDOW (decode_frame_or_selected (con_dev_or_frame));
 }
 
-DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, 1, 1, 0, /*
+DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, 0, 1, 0, /*
 Return non-nil if WINDOW is a minibuffer window.
 */
        (window))
@@ -1437,22 +1437,23 @@ Return the number of columns by which WINDOW is scrolled from left margin.
   return make_int (decode_window (window)->hscroll);
 }
 
-#ifdef MODELINE_IS_SCROLLABLE
 DEFUN ("modeline-hscroll", Fmodeline_hscroll, 0, 1, 0, /*
-Return the number of columns by which WINDOW's modeline is scrolled from
-left margin. If the window has no modeline, return nil.
+Return the horizontal scrolling ammount of WINDOW's modeline.
+If the window has no modeline, return nil.
 */
        (window))
 {
   struct window *w = decode_window (window);
 
-  return (WINDOW_HAS_MODELINE_P (w)) ? make_int (w->modeline_hscroll) : Qnil;
+  return (WINDOW_HAS_MODELINE_P (w)) ? make_int ((int) w->modeline_hscroll) :
+    Qnil;
 }
 
 DEFUN ("set-modeline-hscroll", Fset_modeline_hscroll, 2, 2, 0, /*
-Set number of columns WINDOW's modeline is scrolled from left margin to NCOL.
-NCOL should be zero or positive. If NCOL is negative, it will be forced to 0.
-If the window has no modeline, do nothing and return nil.
+Set the horizontal scrolling ammount of WINDOW's modeline to NCOL.
+If NCOL is negative, it will silently be forced to 0.
+If the window has no modeline, return nil. Otherwise, return the actual
+value that was set.
 */
        (window, ncol))
 {
@@ -1460,18 +1461,20 @@ If the window has no modeline, do nothing and return nil.
 
   if (WINDOW_HAS_MODELINE_P (w))
     {
-      int ncols;
+      Charcount ncols;
+
       CHECK_INT (ncol);
-      ncols = XINT (ncol);
-      if (ncols < 0) ncols = 0;
-      if (w->modeline_hscroll != ncols)
-       MARK_MODELINE_CHANGED;
-      w->modeline_hscroll = ncols;
-      return ncol;
+      ncols = (XINT (ncol) <= 0) ? 0 : (Charcount) XINT (ncol);
+      if (ncols != w->modeline_hscroll)
+       {
+         MARK_MODELINE_CHANGED;
+         w->modeline_hscroll = ncols;
+       }
+      return make_int ((int) ncols);
     }
+
   return Qnil;
 }
-#endif /* MODELINE_IS_SCROLLABLE */
 
 DEFUN ("set-window-hscroll", Fset_window_hscroll, 2, 2, 0, /*
 Set number of columns WINDOW is scrolled from left margin to NCOL.
@@ -1865,6 +1868,12 @@ will automatically call `save-buffers-kill-emacs'.)
   par = XWINDOW (parent);
 
   MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
+  /* It's quite likely that deleting a window will result in
+     subwindows needing to be deleted also (since they are cached
+     per-window). So we mark them as changed, so that the cachels will
+     get reset by redisplay and thus deleted subwindows can get
+     GC'd. */
+  MARK_FRAME_SUBWINDOWS_CHANGED (f);
 
   /* Are we trying to delete any frame's selected window?
      Note that we could be dealing with a non-leaf window
@@ -2596,7 +2605,7 @@ window_loop (enum window_loop type,
                            new_buffer = Fother_buffer (obj, Qnil, Qnil);
                            if (NILP (new_buffer))
                              new_buffer = Fget_buffer_create (QSscratch);
-                           Fset_window_buffer (w, new_buffer);
+                           Fset_window_buffer (w, new_buffer, Qnil);
                            if (EQ (w, Fselected_window (Qnil)))
                              Fset_buffer (p->buffer);
                          }
@@ -2668,7 +2677,7 @@ window_loop (enum window_loop type,
                          /* Otherwise show a different buffer in the
                              window.  */
                          p->dedicated = Qnil;
-                         Fset_window_buffer (w, another_buffer);
+                         Fset_window_buffer (w, another_buffer, Qnil);
                          if (EQ (w, Fselected_window (Qnil)))
                            Fset_buffer (p->buffer);
                        }
@@ -2969,17 +2978,41 @@ check_min_window_sizes (void)
     window_min_height = MIN_SAFE_WINDOW_HEIGHT;
 }
 
+static int
+frame_min_height (struct frame *frame)
+{
+  /* For height, we have to see whether the frame has a minibuffer, and
+     whether it wants a modeline.  */
+  return (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1
+         : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT
+         : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
+}
+
+/* Return non-zero if both frame sizes are less than or equal to
+   minimal allowed values. ROWS and COLS are in characters */
+int
+frame_size_valid_p (struct frame *frame, int rows, int cols)
+{
+  return (rows >= frame_min_height (frame)
+         && cols >= MIN_SAFE_WINDOW_WIDTH);
+}
+
+/* Return non-zero if both frame sizes are less than or equal to
+   minimal allowed values. WIDTH and HEIGHT are in pixels */
+int
+frame_pixsize_valid_p (struct frame *frame, int width, int height)
+{
+  int rows, cols;
+  pixel_to_real_char_size (frame, width, height, &cols, &rows);
+  return frame_size_valid_p (frame, rows, cols);
+}
+
 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
    minimum allowable size.  */
 void
 check_frame_size (struct frame *frame, int *rows, int *cols)
 {
-  /* For height, we have to see whether the frame has a minibuffer, and
-     whether it wants a modeline.  */
-  int min_height =
-    (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1
-     : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT
-     : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
+  int min_height = frame_min_height (frame);
 
   if (*rows < min_height)
     *rows = min_height;
@@ -3129,11 +3162,14 @@ set_window_pixwidth (Lisp_Object window, int new_pixwidth, int nodelete)
 \f
 static int window_select_count;
 
-DEFUN ("set-window-buffer", Fset_window_buffer, 2, 2, 0, /*
+DEFUN ("set-window-buffer", Fset_window_buffer, 2, 3, 0, /*
 Make WINDOW display BUFFER as its contents.
 BUFFER can be a buffer or buffer name.
+
+With non-nil optional argument `norecord', do not modify the
+global or per-frame buffer ordering.
 */
-       (window, buffer))
+       (window, buffer, norecord))
 {
   Lisp_Object tem;
   struct window *w = decode_window (window);
@@ -3192,6 +3228,9 @@ BUFFER can be a buffer or buffer name.
   recompute_all_cached_specifiers_in_window (w);
   if (EQ (window, Fselected_window (Qnil)))
     {
+      if (NILP (norecord))
+       Frecord_buffer (buffer);
+
       Fset_buffer (buffer);
     }
   return Qnil;
@@ -3494,7 +3533,7 @@ and put SIZE columns in the first of the pair.
   /* do this last (after the window is completely initialized and
      the mirror-dirty flag is set) so that specifier recomputation
      caused as a result of this will work properly and not abort. */
-  Fset_window_buffer (new, o->buffer);
+  Fset_window_buffer (new, o->buffer, Qt);
   return new;
 }
 \f
@@ -4042,14 +4081,14 @@ window_scroll (Lisp_Object window, Lisp_Object n, int direction,
 
   if (INTP (Vwindow_pixel_scroll_increment))
     fheight = XINT (Vwindow_pixel_scroll_increment);
-  else if (!NILP (Vwindow_pixel_scroll_increment));
+  else if (!NILP (Vwindow_pixel_scroll_increment))
     default_face_height_and_width (window, &fheight, &fwidth);
-  
+
   if (Dynarr_length (dla) >= 1)
     modeline = Dynarr_atp (dla, 0)->modeline;
 
   dl = Dynarr_atp (dla, modeline);
-    
+
   if (value > 0)
     {
       /* Go for partial display line scrolling. This just means bumping
@@ -4068,7 +4107,7 @@ window_scroll (Lisp_Object window, Lisp_Object n, int direction,
        {
          int vtarget;
          Bufpos startp, old_start;
-         
+
          if (WINDOW_TEXT_TOP_CLIP (w))
            {
              WINDOW_TEXT_TOP_CLIP (w) = 0;
@@ -4077,7 +4116,7 @@ window_scroll (Lisp_Object window, Lisp_Object n, int direction,
 
          old_start = marker_position (w->start[CURRENT_DISP]);
          startp = vmotion (w, old_start, value, &vtarget);
-         
+
          if (vtarget < value &&
              (w->window_end_pos[CURRENT_DISP] == -1
               || (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b))))
@@ -4092,7 +4131,7 @@ window_scroll (Lisp_Object window, Lisp_Object n, int direction,
              w->force_start = 1;
              w->start_at_line_beg = beginning_of_line_p (b, startp);
              MARK_WINDOWS_CHANGED (w);
-             
+
              if (!point_would_be_visible (w, startp, XINT (point)))
                {
                  if (selected)
@@ -4126,16 +4165,16 @@ window_scroll (Lisp_Object window, Lisp_Object n, int direction,
        {
          int vtarget;
          Bufpos startp, old_start;
-         
+
          if (WINDOW_TEXT_TOP_CLIP (w))
            {
              WINDOW_TEXT_TOP_CLIP (w) = 0;
              MARK_WINDOWS_CHANGED (w);
            }
-             
+
          old_start = marker_position (w->start[CURRENT_DISP]);
          startp = vmotion (w, old_start, value, &vtarget);
-         
+
          if (vtarget > value
              && marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
            {
@@ -4149,16 +4188,34 @@ window_scroll (Lisp_Object window, Lisp_Object n, int direction,
              w->force_start = 1;
              w->start_at_line_beg = beginning_of_line_p (b, startp);
              MARK_WINDOWS_CHANGED (w);
-             
+
+             /* #### Scroll back by less than a line. This code was
+                originally for scrolling over large pixmaps and it
+                loses when a line being *exposed* at the top of the
+                window is bigger than the current one. However, for
+                pixel based scrolling in general we can guess that
+                the line we are going to display is probably the same
+                size as the one we are on. In that instance we can
+                have a reasonable stab at a suitable top clip. Fixing
+                this properly is hard (and probably slow) as we would
+                have to call redisplay to figure out the exposed line
+                size. */
+             if (!NILP (Vwindow_pixel_scroll_increment)
+                 && Dynarr_length (dla) >= (1 + modeline)
+                 && dl->ascent + fheight * value > 0)
+               {
+                 WINDOW_TEXT_TOP_CLIP (w) = (dl->ascent + fheight * value);
+               }
+
              if (!point_would_be_visible (w, startp, XINT (point)))
                {
                  Bufpos new_point;
-                 
+
                  if (MINI_WINDOW_P (w))
                    new_point = startp;
                  else
                    new_point = start_of_last_line (w, startp);
-                 
+
                  if (selected)
                    BUF_SET_PT (b, new_point);
                  else
@@ -4688,7 +4745,7 @@ struct saved_window
   int pixel_width;
   int pixel_height;
   int hscroll;
-  int modeline_hscroll;
+  Charcount modeline_hscroll;
   int parent_index;           /* index into saved_windows */
   int prev_index;             /* index into saved_windows */
   char start_at_line_beg; /* boolean */
@@ -4725,7 +4782,6 @@ struct window_config
 #define XWINDOW_CONFIGURATION(x) XRECORD (x, window_configuration, struct window_config)
 #define XSETWINDOW_CONFIGURATION(x, p) XSETRECORD (x, p, window_configuration)
 #define WINDOW_CONFIGURATIONP(x) RECORDP (x, window_configuration)
-#define GC_WINDOW_CONFIGURATIONP(x) GC_RECORDP (x, window_configuration)
 #define CHECK_WINDOW_CONFIGURATION(x) CHECK_RECORD (x, window_configuration)
 
 static Lisp_Object
@@ -4951,7 +5007,7 @@ by `current-window-configuration' (which see).
   int previous_pixel_width;
   int previous_minibuf_height, previous_minibuf_top,previous_minibuf_width;
   int real_font_height;
-  int converted_minibuf_height,target_minibuf_height; 
+  int converted_minibuf_height,target_minibuf_height;
   int specpdl_count = specpdl_depth ();
 
   GCPRO1 (configuration);
@@ -5019,7 +5075,7 @@ by `current-window-configuration' (which see).
 #if 0
       /* JV: This is bogus,
         First of all, the units are inconsistent. The frame sizes are measured
-        in characters but the window sizes are stored in pixels. So if a 
+        in characters but the window sizes are stored in pixels. So if a
         font size change happened between saving and restoring, the
         frame "sizes" maybe equal but the windows still should be
         resized. This is tickled alot by the new "character size
@@ -5040,7 +5096,7 @@ by `current-window-configuration' (which see).
          || config->frame_width != FRAME_WIDTH (f))
        change_frame_size (f, config->frame_height, config->frame_width, 0);
 #endif
-      
+
       previous_pixel_top = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top;
       previous_pixel_height = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_height;
       previous_pixel_left = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left;
@@ -5050,7 +5106,7 @@ by `current-window-configuration' (which see).
 
       default_face_height_and_width (frame, &real_font_height, 0);
       assert(real_font_height > 0);
-  
+
       if (FRAME_HAS_MINIBUF_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
        {
          previous_minibuf_height
@@ -5063,13 +5119,14 @@ by `current-window-configuration' (which see).
       else
        {
          previous_minibuf_height = 0;
+         previous_minibuf_top = 0;
          previous_minibuf_width = 0;
        }
       converted_minibuf_height =
        (previous_minibuf_height % real_font_height) == 0 ?
        - (previous_minibuf_height / real_font_height ) :    /* lines */
            previous_minibuf_height;   /* pixels */
-           
+
       /* Temporarily avoid any problems with windows that are smaller
         than they are supposed to be.  */
       window_min_height = 1;
@@ -5251,7 +5308,7 @@ by `current-window-configuration' (which see).
 
          #### Now we get more cases correct then ever before, but
         are we treating all? For instance what if the frames minibuf window
-        is no longer the same one? 
+        is no longer the same one?
       */
       target_minibuf_height = previous_minibuf_height;
       if (converted_minibuf_height &&
@@ -5274,7 +5331,7 @@ by `current-window-configuration' (which see).
          set_window_pixwidth  (FRAME_MINIBUF_WINDOW (f),
                            previous_minibuf_width, 0);
        }
-       
+
       /* This is a better way to deal with frame resizing, etc.
         What we _actually_ want is for the old (just restored)
         root window to fit
@@ -5289,7 +5346,7 @@ by `current-window-configuration' (which see).
       /* Note that this function also updates the subwindow
         "pixel_left"s */
       set_window_pixwidth (FRAME_ROOT_WINDOW (f), previous_pixel_width, 0);
-      
+
       /* If restoring in the current frame make the window current,
         otherwise just update the frame selected_window slot to be
         the restored current_window. */
@@ -5531,11 +5588,11 @@ its value is -not- saved.
 
   /* save the minibuffer height using the heuristics from
      change_frame_size_1 */
-  
+
   XSETFRAME (frame, f); /* frame could have been nil ! */
   default_face_height_and_width (frame, &real_font_height, 0);
   assert(real_font_height > 0);
-  
+
   if (FRAME_HAS_MINIBUF_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
     minibuf_height = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
   else
@@ -5601,7 +5658,7 @@ a non-nil result to be returned.
 
       if (NILP (pos))
        pos = Fwindow_point (window);
-      
+
       CHECK_INT (pos);
       point = XINT (pos);
 
@@ -5739,15 +5796,13 @@ syms_of_window (void)
   DEFSUBR (Fwindow_displayed_text_pixel_height);
   DEFSUBR (Fwindow_text_area_pixel_width);
   DEFSUBR (Fwindow_hscroll);
-#ifdef MODELINE_IS_SCROLLABLE
+  DEFSUBR (Fset_window_hscroll);
   DEFSUBR (Fmodeline_hscroll);
   DEFSUBR (Fset_modeline_hscroll);
-#endif /* MODELINE_IS_SCROLLABLE */
 #if 0 /* bogus FSF crock */
   DEFSUBR (Fwindow_redisplay_end_trigger);
   DEFSUBR (Fset_window_redisplay_end_trigger);
 #endif
-  DEFSUBR (Fset_window_hscroll);
   DEFSUBR (Fwindow_pixel_edges);
   DEFSUBR (Fwindow_text_area_pixel_edges);
   DEFSUBR (Fwindow_point);
@@ -5887,8 +5942,7 @@ This is a specifier; use `set-specifier' to change it.
   Fadd_spec_to_specifier (Vmodeline_shadow_thickness, make_int (2),
                          Qnil, Qnil, Qnil);
   set_specifier_caching (Vmodeline_shadow_thickness,
-                        slot_offset (struct window,
-                                     modeline_shadow_thickness),
+                        offsetof (struct window, modeline_shadow_thickness),
                         modeline_shadow_thickness_changed,
                         0, 0);
 
@@ -5900,8 +5954,7 @@ This is a specifier; use `set-specifier' to change it.
   set_specifier_fallback (Vhas_modeline_p,
                          list1 (Fcons (Qnil, Qt)));
   set_specifier_caching (Vhas_modeline_p,
-                        slot_offset (struct window,
-                                     has_modeline_p),
+                        offsetof (struct window, has_modeline_p),
                         /* #### It's strange that we need a special
                            flag to indicate that the shadow-thickness
                            has changed, but not one to indicate that
@@ -5923,8 +5976,8 @@ This is a specifier; use `set-specifier' to change it.
   set_specifier_fallback (Vvertical_divider_always_visible_p,
                          list1 (Fcons (Qnil, Qt)));
   set_specifier_caching (Vvertical_divider_always_visible_p,
-                        slot_offset (struct window,
-                                     vertical_divider_always_visible_p),
+                        offsetof (struct window,
+                                  vertical_divider_always_visible_p),
                         vertical_divider_changed_in_window,
                         0, 0);
 
@@ -5938,8 +5991,8 @@ This is a specifier; use `set-specifier' to change it.
   Fadd_spec_to_specifier (Vvertical_divider_shadow_thickness, make_int (2),
                          Qnil, Qnil, Qnil);
   set_specifier_caching (Vvertical_divider_shadow_thickness,
-                        slot_offset (struct window,
-                                     vertical_divider_shadow_thickness),
+                        offsetof (struct window,
+                                  vertical_divider_shadow_thickness),
                         vertical_divider_changed_in_window,
                         0, 0);
   DEFVAR_SPECIFIER ("vertical-divider-line-width", &Vvertical_divider_line_width /*
@@ -5969,8 +6022,8 @@ This is a specifier; use `set-specifier' to change it.
     set_specifier_fallback (Vvertical_divider_line_width, fb);
   }
   set_specifier_caching (Vvertical_divider_line_width,
-                         slot_offset (struct window,
-                                     vertical_divider_line_width),
+                         offsetof (struct window,
+                                  vertical_divider_line_width),
                         vertical_divider_changed_in_window,
                          0, 0);
 
@@ -5999,8 +6052,7 @@ This is a specifier; use `set-specifier' to change it.
     set_specifier_fallback (Vvertical_divider_spacing, fb);
   }
   set_specifier_caching (Vvertical_divider_spacing,
-                        slot_offset (struct window,
-                                     vertical_divider_spacing),
+                        offsetof (struct window, vertical_divider_spacing),
                         vertical_divider_changed_in_window,
                         0, 0);
 }