From 266821b087057c25c5f7169d832b0bdc8b8a0aa5 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Sat, 16 Aug 2014 17:47:38 +0200 Subject: [PATCH] Preliminary attempt to fix horizontal scroll bar dragging with bidi text. * w32term.c (w32_horizontal_scroll_bar_handle_click): In y part of emacs_event return length from si.nPage to si.nMax. * xdisp.c (set_horizontal_scroll_bar): For right-to-left text interchange start and end of thumb. * scroll-bar.el (scroll-bar-horizontal-drag-1): Use cdr of portion-whole for scrolling right-to-left text. --- lisp/ChangeLog | 5 +++++ lisp/scroll-bar.el | 7 +++++-- src/ChangeLog | 7 +++++++ src/w32term.c | 8 ++++---- src/xdisp.c | 29 ++++++++++++++++++++--------- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f96921d4329..b474e87caa1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2014-08-16 Martin Rudalics + + * scroll-bar.el (scroll-bar-horizontal-drag-1): Use cdr of + portion-whole for scrolling right-to-left text. + 2014-08-15 Leo Liu * speedbar.el (speedbar-generic-list-tag-p): Allow special diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el index 739670cb1c9..1af70b0d631 100644 --- a/lisp/scroll-bar.el +++ b/lisp/scroll-bar.el @@ -327,8 +327,11 @@ If you click outside the slider, the window scrolls to bring the slider there." (window (nth 0 start-position)) (portion-whole (nth 2 start-position)) (unit (frame-char-width (window-frame window)))) - (set-window-hscroll - window (/ (1- (+ (car portion-whole) unit)) unit)))) + (if (eq (current-bidi-paragraph-direction) 'left-to-right) + (set-window-hscroll + window (/ (1- (+ (car portion-whole) unit)) unit)) + (set-window-hscroll + window (/ (1- (+ (cdr portion-whole) unit)) unit))))) (defun scroll-bar-horizontal-drag (event) "Scroll the window horizontally by dragging the scroll bar slider. diff --git a/src/ChangeLog b/src/ChangeLog index 91b72e479d7..8e6e75e8b53 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2014-08-16 Martin Rudalics + + * w32term.c (w32_horizontal_scroll_bar_handle_click): In y part + of emacs_event return length from si.nPage to si.nMax. + * xdisp.c (set_horizontal_scroll_bar): For right-to-left text + interchange start and end of thumb. + 2014-08-15 Ken Brown * gmalloc.c (_malloc_mutex, _aligned_blocks_mutex) [CYGWIN]: Use diff --git a/src/w32term.c b/src/w32term.c index dfda29fb903..4eff5ab4cdd 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -4272,15 +4272,15 @@ w32_horizontal_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg, { int left_range = HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f, bar->width); - int x; + int x, y; int dragging = bar->dragging; SCROLLINFO si; si.cbSize = sizeof (si); - si.fMask = SIF_POS; - + si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; GetScrollInfo ((HWND) msg->msg.lParam, SB_CTL, &si); x = si.nPos; + y = si.nMax - si.nPos - si.nPage; bar->dragging = 0; FRAME_DISPLAY_INFO (f)->last_mouse_scroll_bar_pos = msg->msg.wParam; @@ -4354,7 +4354,7 @@ w32_horizontal_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg, } XSETINT (emacs_event->x, x); - XSETINT (emacs_event->y, left_range); + XSETINT (emacs_event->y, y); return TRUE; } diff --git a/src/xdisp.c b/src/xdisp.c index fe16b2c6a07..c46b4159de0 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -15779,7 +15779,7 @@ set_vertical_scroll_bar (struct window *w) void set_horizontal_scroll_bar (struct window *w) { - int start, end, whole, box_width; + int start, end, whole, portion; if (!MINI_WINDOW_P (w) || (w == XWINDOW (minibuf_window) @@ -15806,14 +15806,25 @@ set_horizontal_scroll_bar (struct window *w) MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */ start = w->hscroll * FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w)); - box_width = window_box_width (w, TEXT_AREA); - end = start + box_width; + end = start + window_box_width (w, TEXT_AREA); + portion = end - start; + /* After enlarging a horizontally scrolled window such that it + gets at least as wide as the text it contains, make sure that + the thumb doesn't fill the entire scroll bar so we can still + drag it back to see the entire text. */ + whole = max (whole, end); - /* The following is needed to ensure that if after maximizing a - window we get hscroll > 0, we can still drag the thumb to the - left. */ - whole = max (whole, w->hscroll + box_width); - whole = max (whole, end - start); + if (it.bidi_p) + { + Lisp_Object pdir; + + pdir = Fcurrent_bidi_paragraph_direction (Qnil); + if (EQ (pdir, Qright_to_left)) + { + start = whole - end; + end = start + portion; + } + } if (old_buffer) set_buffer_internal (old_buffer); @@ -15826,7 +15837,7 @@ set_horizontal_scroll_bar (struct window *w) /* Indicate what this scroll bar ought to be displaying now. */ if (FRAME_TERMINAL (XFRAME (w->frame))->set_horizontal_scroll_bar_hook) (*FRAME_TERMINAL (XFRAME (w->frame))->set_horizontal_scroll_bar_hook) - (w, end - start, whole, start); + (w, portion, whole, start); } -- 2.39.5