]> code.delx.au - gnu-emacs/commitdiff
Some fixes for scroll bar code.
authorMartin Rudalics <rudalics@gmx.at>
Thu, 28 Aug 2014 06:46:58 +0000 (08:46 +0200)
committerMartin Rudalics <rudalics@gmx.at>
Thu, 28 Aug 2014 06:46:58 +0000 (08:46 +0200)
* w32term.c (w32_horizontal_scroll_bar_handle_click): In
`event->y' return entire range (the size of the scroll bar minus
that of the thumb).
* xterm.c (xm_scroll_callback, xaw_jump_callback): In `whole'
return entire range (the scaled size of the scroll bar minus
that of the slider).  In `portion' return the scaled position of
the slider.
(xaw_jump_callback): Restore part of code for vertical scroll
bar broken in change from 2014-07-27.
(xaw_scroll_callback): Provide incremental scrolling with
horizontal scroll bars.
(x_scroll_bar_handle_click): Fix typo introduced in change from
2014-07-27.
* scroll-bar.el (scroll-bar-horizontal-drag-1): Handle new
interpretation of `portion-whole'.

lisp/ChangeLog
lisp/scroll-bar.el
src/ChangeLog
src/w32term.c
src/xterm.c

index 73f3287ed40415b21186f0a79b3d54352506ddcf..a8e6eb80f5d475176bdfb0cb09c84adec6010e16 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-28  Martin Rudalics  <rudalics@gmx.at>
+
+       * scroll-bar.el (scroll-bar-horizontal-drag-1): Handle new
+       interpretation of `portion-whole'.
+
 2014-08-28  Michael Albinus  <michael.albinus@gmx.de>
 
        * emacs-lisp/authors.el (authors-aliases): Addition.
index f803eb7f9289b5fe02fb467835748c0f1ee3aa13..2dd394fa2af6cfbbb71f44c23d2fbd82f42ec21f 100644 (file)
@@ -330,9 +330,11 @@ If you click outside the slider, the window scrolls to bring the slider there."
     (if (eq (current-bidi-paragraph-direction (window-buffer window))
            'left-to-right)
        (set-window-hscroll
-        window (/ (1- (+ (car portion-whole) unit)) unit))
+        window (/ (+ (car portion-whole) (1- unit)) unit))
       (set-window-hscroll
-        window (/ (1- (+ (cdr portion-whole) unit)) unit)))))
+       window (/ (+ (- (cdr portion-whole) (car portion-whole))
+                   (1- unit))
+                unit)))))
 
 (defun scroll-bar-horizontal-drag (event)
   "Scroll the window horizontally by dragging the scroll bar slider.
index d08b3780242753b9cee581f37fba91132600fe87..d0eec16a60a4567e72f0902fdc591ac39f39d1e7 100644 (file)
@@ -1,3 +1,19 @@
+2014-08-28  Martin Rudalics  <rudalics@gmx.at>
+
+       * w32term.c (w32_horizontal_scroll_bar_handle_click): In
+       `event->y' return entire range (the size of the scroll bar minus
+       that of the thumb).
+       * xterm.c (xm_scroll_callback, xaw_jump_callback): In `whole'
+       return entire range (the scaled size of the scroll bar minus
+       that of the slider).  In `portion' return the scaled position of
+       the slider.
+       (xaw_jump_callback): Restore part of code for vertical scroll
+       bar broken in change from 2014-07-27.
+       (xaw_scroll_callback): Provide incremental scrolling with
+       horizontal scroll bars.
+       (x_scroll_bar_handle_click): Fix typo introduced in change from
+       2014-07-27.
+
 2014-08-28  Eli Zaretskii  <eliz@gnu.org>
 
        * conf_post.h (_GL_EXECINFO_INLINE) [MSDOS]: Don't define.
index d9e051be870cfc49dbfe6fcc1e913579438b57b1..55c2d718346a2da87435755249237f0dd73e7ec3 100644 (file)
@@ -4293,7 +4293,7 @@ w32_horizontal_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg,
       x = si.nTrackPos;
     else
       x = si.nPos;
-    y = si.nMax - x - si.nPage;
+    y = si.nMax - si.nPage;
 
     bar->dragging = 0;
     FRAME_DISPLAY_INFO (f)->last_mouse_scroll_bar_pos = msg->msg.wParam;
@@ -4350,12 +4350,9 @@ w32_horizontal_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg,
            int end = bar->end;
 
            si.cbSize = sizeof (si);
-/**        si.fMask = SIF_PAGE | SIF_POS; **/
            si.fMask = SIF_POS;
-/**        si.nPage = end - start + HORIZONTAL_SCROLL_BAR_MIN_HANDLE; **/
            si.nPos = min (last_scroll_bar_drag_pos,
                           XWINDOW (bar->window)->hscroll_whole - 1);
-/**        si.nPos = last_scroll_bar_drag_pos; **/
            SetScrollInfo (SCROLL_BAR_W32_WINDOW (bar), SB_CTL, &si, TRUE);
          }
        /* fall through */
index 7b8d32a45160d802b1d7023d03b5ec59fb2cdd59..e4a725a4ab1f51ddf9fab2c7d4ce79eb37ac6089 100644 (file)
@@ -4549,12 +4549,9 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
 
        if (horizontal)
          {
-           whole = bar->whole;
-           portion = (((float) cs->value
-                       / (XM_SB_MAX - slider_size))
-                      * (whole
-                         - ((float) slider_size / XM_SB_MAX) * whole));
-           portion = max (0, portion);
+           portion = bar->whole * ((float)cs->value / XM_SB_MAX);
+           whole = bar->whole * ((float)(XM_SB_MAX - slider_size) / XM_SB_MAX);
+           portion = min (portion, whole);
            part = scroll_bar_horizontal_handle;
          }
        else
@@ -4687,24 +4684,51 @@ xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
   float *top_addr = call_data;
   float top = *top_addr;
   float shown;
-  int whole, portion, height;
+  int whole, portion, height, width;
   enum scroll_bar_part part;
   int horizontal = bar->horizontal;
 
-  /* Get the size of the thumb, a value between 0 and 1.  */
-  block_input ();
-  XtVaGetValues (widget, XtNshown, &shown, XtNheight, &height, NULL);
-  unblock_input ();
 
   if (horizontal)
     {
-      whole = bar->whole;
-      portion = (top * (whole - (shown * whole))) / (1 - shown);
-      portion = max (0, portion);
+      /* Get the size of the thumb, a value between 0 and 1.  */
+      block_input ();
+      XtVaGetValues (widget, XtNshown, &shown, XtNwidth, &width, NULL);
+      unblock_input ();
+
+      if (shown < 1)
+       {
+         whole = bar->whole - (shown * bar->whole);
+         portion = min (top * bar->whole, whole);
+       }
+      else
+       {
+         whole = bar->whole;
+         portion = 0;
+       }
+
       part = scroll_bar_horizontal_handle;
     }
   else
-    part = scroll_bar_handle;
+    {
+      /* Get the size of the thumb, a value between 0 and 1.  */
+      block_input ();
+      XtVaGetValues (widget, XtNshown, &shown, XtNheight, &height, NULL);
+      unblock_input ();
+
+      whole = 10000000;
+      portion = shown < 1 ? top * whole : 0;
+
+      if (shown < 1 && (eabs (top + shown - 1) < 1.0f / height))
+       /* Some derivatives of Xaw refuse to shrink the thumb when you reach
+          the bottom, so we force the scrolling whenever we see that we're
+          too close to the bottom (in x_set_toolkit_scroll_bar_thumb
+          we try to ensure that we always stay two pixels away from the
+          bottom).  */
+       part = scroll_bar_down_arrow;
+      else
+       part = scroll_bar_handle;
+    }
 
   window_being_scrolled = bar->window;
   bar->dragging = portion;
@@ -4727,28 +4751,54 @@ xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
   struct scroll_bar *bar = client_data;
   /* The position really is stored cast to a pointer.  */
   int position = (intptr_t) call_data;
-  Dimension height;
+  Dimension height, width;
   enum scroll_bar_part part;
 
-  /* Get the height of the scroll bar.  */
-  block_input ();
-  XtVaGetValues (widget, XtNheight, &height, NULL);
-  unblock_input ();
+  if (bar->horizontal)
+    {
+      /* Get the width of the scroll bar.  */
+      block_input ();
+      XtVaGetValues (widget, XtNwidth, &width, NULL);
+      unblock_input ();
+
+      if (eabs (position) >= width)
+       part = (position < 0) ? scroll_bar_before_handle : scroll_bar_after_handle;
 
-  if (eabs (position) >= height)
-    part = (position < 0) ? scroll_bar_above_handle : scroll_bar_below_handle;
+      /* If Xaw3d was compiled with ARROW_SCROLLBAR,
+        it maps line-movement to call_data = max(5, height/20).  */
+      else if (xaw3d_arrow_scroll && eabs (position) <= max (5, width / 20))
+       part = (position < 0) ? scroll_bar_left_arrow : scroll_bar_right_arrow;
+      else
+       part = scroll_bar_move_ratio;
 
-  /* If Xaw3d was compiled with ARROW_SCROLLBAR,
-     it maps line-movement to call_data = max(5, height/20).  */
-  else if (xaw3d_arrow_scroll && eabs (position) <= max (5, height / 20))
-    part = (position < 0) ? scroll_bar_up_arrow : scroll_bar_down_arrow;
+      window_being_scrolled = bar->window;
+      bar->dragging = -1;
+      bar->last_seen_part = part;
+      x_send_scroll_bar_event (bar->window, part, position, width, bar->horizontal);
+    }
   else
-    part = scroll_bar_move_ratio;
+    {
 
-  window_being_scrolled = bar->window;
-  bar->dragging = -1;
-  bar->last_seen_part = part;
-  x_send_scroll_bar_event (bar->window, part, position, height, bar->horizontal);
+      /* Get the height of the scroll bar.  */
+      block_input ();
+      XtVaGetValues (widget, XtNheight, &height, NULL);
+      unblock_input ();
+
+      if (eabs (position) >= height)
+       part = (position < 0) ? scroll_bar_above_handle : scroll_bar_below_handle;
+
+      /* If Xaw3d was compiled with ARROW_SCROLLBAR,
+        it maps line-movement to call_data = max(5, height/20).  */
+      else if (xaw3d_arrow_scroll && eabs (position) <= max (5, height / 20))
+       part = (position < 0) ? scroll_bar_up_arrow : scroll_bar_down_arrow;
+      else
+       part = scroll_bar_move_ratio;
+
+      window_being_scrolled = bar->window;
+      bar->dragging = -1;
+      bar->last_seen_part = part;
+      x_send_scroll_bar_event (bar->window, part, position, height, bar->horizontal);
+    }
 }
 
 #endif /* not USE_GTK and not USE_MOTIF */
@@ -6134,7 +6184,7 @@ x_scroll_bar_handle_click (struct scroll_bar *bar,
       /* If the user has released the handle, set it to its final position.  */
       if (event->type == ButtonRelease && bar->dragging != -1)
        {
-         int new_start =  - bar->dragging;
+         int new_start = y - bar->dragging;
          int new_end = new_start + bar->end - bar->start;
 
          x_scroll_bar_set_handle (bar, new_start, new_end, 0);