patch 9.0.0886: horizontal mouse scroll only works in the GUI

Problem:    Horizontal mouse scroll only works in the GUI.
Solution:   Make horizontal mouse scroll also work in a terminal.
            (Christopher Plewright, closes #11448)
diff --git a/src/gui.c b/src/gui.c
index 88c0a13..45747ef 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -4105,14 +4105,14 @@
 	scrollbar_value = value;
 
 	if (State & MODE_NORMAL)
-	    gui_do_horiz_scroll(scrollbar_value, FALSE);
+	    do_mousescroll_horiz(scrollbar_value);
 	else if (State & MODE_INSERT)
 	    ins_horscroll();
 	else if (State & MODE_CMDLINE)
 	{
 	    if (msg_scrolled == 0)
 	    {
-		gui_do_horiz_scroll(scrollbar_value, FALSE);
+		do_mousescroll_horiz(scrollbar_value);
 		redrawcmdline();
 	    }
 	}
@@ -4504,88 +4504,13 @@
     return (wp == curwin && !EQUAL_POS(curwin->w_cursor, old_cursor));
 }
 
-
 /*
  * Horizontal scrollbar stuff:
  */
-
-/*
- * Return length of line "lnum" for horizontal scrolling.
- */
-    static colnr_T
-scroll_line_len(linenr_T lnum)
-{
-    char_u	*p;
-    colnr_T	col;
-    int		w;
-
-    p = ml_get(lnum);
-    col = 0;
-    if (*p != NUL)
-	for (;;)
-	{
-	    w = chartabsize(p, col);
-	    MB_PTR_ADV(p);
-	    if (*p == NUL)		// don't count the last character
-		break;
-	    col += w;
-	}
-    return col;
-}
-
-// Remember which line is currently the longest, so that we don't have to
-// search for it when scrolling horizontally.
-static linenr_T longest_lnum = 0;
-
-/*
- * Find longest visible line number.  If this is not possible (or not desired,
- * by setting 'h' in "guioptions") then the current line number is returned.
- */
-    static linenr_T
-gui_find_longest_lnum(void)
-{
-    linenr_T ret = 0;
-
-    // Calculate maximum for horizontal scrollbar.  Check for reasonable
-    // line numbers, topline and botline can be invalid when displaying is
-    // postponed.
-    if (vim_strchr(p_go, GO_HORSCROLL) == NULL
-	    && curwin->w_topline <= curwin->w_cursor.lnum
-	    && curwin->w_botline > curwin->w_cursor.lnum
-	    && curwin->w_botline <= curbuf->b_ml.ml_line_count + 1)
-    {
-	linenr_T    lnum;
-	colnr_T	    n;
-	long	    max = 0;
-
-	// Use maximum of all visible lines.  Remember the lnum of the
-	// longest line, closest to the cursor line.  Used when scrolling
-	// below.
-	for (lnum = curwin->w_topline; lnum < curwin->w_botline; ++lnum)
-	{
-	    n = scroll_line_len(lnum);
-	    if (n > (colnr_T)max)
-	    {
-		max = n;
-		ret = lnum;
-	    }
-	    else if (n == (colnr_T)max
-		    && abs((int)(lnum - curwin->w_cursor.lnum))
-		       < abs((int)(ret - curwin->w_cursor.lnum)))
-		ret = lnum;
-	}
-    }
-    else
-	// Use cursor line only.
-	ret = curwin->w_cursor.lnum;
-
-    return ret;
-}
-
     static void
 gui_update_horiz_scrollbar(int force)
 {
-    long	value, size, max;	// need 32 bit ints here
+    long	value, size, max;
 
     if (!gui.which_scrollbars[SBAR_BOTTOM])
 	return;
@@ -4619,9 +4544,7 @@
     else
     {
 	value = curwin->w_leftcol;
-
-	longest_lnum = gui_find_longest_lnum();
-	max = scroll_line_len(longest_lnum);
+	max = scroll_line_len(ui_find_longest_lnum());
 
 	if (virtual_active())
 	{
@@ -4670,44 +4593,6 @@
 }
 
 /*
- * Do a horizontal scroll.  Return TRUE if the cursor moved, FALSE otherwise.
- */
-    int
-gui_do_horiz_scroll(long_u leftcol, int compute_longest_lnum)
-{
-    // no wrapping, no scrolling
-    if (curwin->w_p_wrap)
-	return FALSE;
-
-    if (curwin->w_leftcol == (colnr_T)leftcol)
-	return FALSE;
-
-    curwin->w_leftcol = (colnr_T)leftcol;
-
-    // When the line of the cursor is too short, move the cursor to the
-    // longest visible line.
-    if (vim_strchr(p_go, GO_HORSCROLL) == NULL
-	    && !virtual_active()
-	    && (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum))
-    {
-	if (compute_longest_lnum)
-	{
-	    curwin->w_cursor.lnum = gui_find_longest_lnum();
-	    curwin->w_cursor.col = 0;
-	}
-	// Do a sanity check on "longest_lnum", just in case.
-	else if (longest_lnum >= curwin->w_topline
-		&& longest_lnum < curwin->w_botline)
-	{
-	    curwin->w_cursor.lnum = longest_lnum;
-	    curwin->w_cursor.col = 0;
-	}
-    }
-
-    return leftcol_changed();
-}
-
-/*
  * Check that none of the colors are the same as the background color
  */
     void