Patch 8.2.4874
Problem:    Win32 GUI: horizontal scroll wheel not handled properly.
Solution:   Also handle WM_MOUSEHWHEEL. (closes #10309)
Files:      src/gui_w32.c


*** ../vim-8.2.4873/src/gui_w32.c       2022-04-28 19:50:48.158411708 +0100
--- src/gui_w32.c       2022-05-05 19:22:30.323918818 +0100
***************
*** 219,225 ****
  #define DLG_NONBUTTON_CONTROL 5000    // First ID of non-button controls
  
  #ifndef WM_DPICHANGED
! # define WM_DPICHANGED                0x02E0
  #endif
  
  #ifdef PROTO
--- 219,233 ----
  #define DLG_NONBUTTON_CONTROL 5000    // First ID of non-button controls
  
  #ifndef WM_DPICHANGED
! # define WM_DPICHANGED                        0x02E0
! #endif
! 
! #ifndef WM_MOUSEHWHEEL
! # define WM_MOUSEHWHEEL                       0x020E
! #endif
! 
! #ifndef SPI_GETWHEELSCROLLCHARS
! # define SPI_GETWHEELSCROLLCHARS      0x006C
  #endif
  
  #ifdef PROTO
***************
*** 3992,3997 ****
--- 4000,4006 ----
  
  // Intellimouse support
  static int mouse_scroll_lines = 0;
+ static int mouse_scroll_chars = 0;
  
  #ifdef FEAT_TOOLBAR
  static void initialise_toolbar(void);
***************
*** 4111,4121 ****
      static void
  init_mouse_wheel(void)
  {
!     mouse_scroll_lines = 3;   // reasonable default
  
      // if NT 4.0+ (or Win98) get scroll lines directly from system
!     SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
!           &mouse_scroll_lines, 0);
  }
  
  
--- 4120,4132 ----
      static void
  init_mouse_wheel(void)
  {
!     // Reasonable default values.
!     mouse_scroll_lines = 3;
!     mouse_scroll_chars = 3;
  
      // if NT 4.0+ (or Win98) get scroll lines directly from system
!     SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &mouse_scroll_lines, 0);
!     SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &mouse_scroll_chars, 0);
  }
  
  
***************
*** 4124,4138 ****
   * Treat a mouse wheel event as if it were a scroll request.
   */
      static void
! _OnMouseWheel(
!     HWND hwnd,
!     short zDelta)
  {
!     int i;
!     int size;
!     HWND hwndCtl;
!     win_T *wp;
  
      if (mouse_scroll_lines == 0)
        init_mouse_wheel();
  
--- 4135,4149 ----
   * Treat a mouse wheel event as if it were a scroll request.
   */
      static void
! _OnMouseWheel(HWND hwnd, short zDelta, LPARAM param, int horizontal)
  {
!     int               i;
!     int               amount;
!     int               button;
!     win_T     *wp;
!     int               modifiers, kbd_modifiers;
  
+     // Initializes mouse_scroll_chars too.
      if (mouse_scroll_lines == 0)
        init_mouse_wheel();
  
***************
*** 4148,4155 ****
        mouse_row = wp->w_winrow;
        mouse_col = wp->w_wincol;
        CLEAR_FIELD(cap);
!       cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN;
!       cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN;
        clear_oparg(&oa);
        cap.oap = &oa;
        nv_mousescroll(&cap);
--- 4159,4174 ----
        mouse_row = wp->w_winrow;
        mouse_col = wp->w_wincol;
        CLEAR_FIELD(cap);
!       if (horizontal)
!       {
!           cap.arg = zDelta < 0 ? MSCR_LEFT : MSCR_RIGHT;
!           cap.cmdchar = zDelta < 0 ? K_MOUSELEFT : K_MOUSERIGHT;
!       }
!       else
!       {
!           cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN;
!           cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN;
!       }
        clear_oparg(&oa);
        cap.oap = &oa;
        nv_mousescroll(&cap);
***************
*** 4163,4185 ****
      if (wp == NULL || !p_scf)
        wp = curwin;
  
!     if (wp->w_scrollbars[SBAR_RIGHT].id != 0)
!       hwndCtl = wp->w_scrollbars[SBAR_RIGHT].id;
!     else if (wp->w_scrollbars[SBAR_LEFT].id != 0)
!       hwndCtl = wp->w_scrollbars[SBAR_LEFT].id;
      else
-       return;
-     size = wp->w_height;
- 
-     mch_disable_flush();
-     if (mouse_scroll_lines > 0
-           && mouse_scroll_lines < (size > 2 ? size - 2 : 1))
      {
!       for (i = mouse_scroll_lines; i > 0; --i)
!           _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_LINEUP : SB_LINEDOWN, 0);
      }
!     else
!       _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_PAGEUP : SB_PAGEDOWN, 0);
      mch_enable_flush();
      gui_may_flush();
  }
--- 4182,4221 ----
      if (wp == NULL || !p_scf)
        wp = curwin;
  
!     // Translate the scroll event into an event that Vim can process so that
!     // the user has a chance to map the scrollwheel buttons.
!     if (horizontal)
!     {
!       button = zDelta >= 0 ? MOUSE_6 : MOUSE_7;
!       if (mouse_scroll_chars > 0
!                              && mouse_scroll_chars < MAX(wp->w_width - 2, 1))
!           amount = mouse_scroll_chars;
!       else
!           amount = MAX(wp->w_width - 2, 1);
!     }
      else
      {
!       button = zDelta >= 0 ? MOUSE_4 : MOUSE_5;
!       if (mouse_scroll_lines > 0
!                             && mouse_scroll_lines < MAX(wp->w_height - 2, 1))
!           amount = mouse_scroll_lines;
!       else
!           amount = MAX(wp->w_height - 2, 1);
      }
! 
!     kbd_modifiers = get_active_modifiers();
! 
!     if ((kbd_modifiers & MOD_MASK_SHIFT) != 0)
!       modifiers |= MOUSE_SHIFT;
!     if ((kbd_modifiers & MOD_MASK_CTRL) != 0)
!       modifiers |= MOUSE_CTRL;
!     if ((kbd_modifiers & MOD_MASK_ALT) != 0)
!       modifiers |= MOUSE_ALT;
! 
!     mch_disable_flush();
!     for (i = amount; i > 0; --i)
!       gui_send_mouse_event(button, GET_X_LPARAM(param), GET_Y_LPARAM(param),
!               FALSE, kbd_modifiers);
      mch_enable_flush();
      gui_may_flush();
  }
***************
*** 4255,4267 ****
   * Invoked when a setting was changed.
   */
      static LRESULT CALLBACK
! _OnSettingChange(UINT n)
  {
!     if (n == SPI_SETWHEELSCROLLLINES)
!       SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
!               &mouse_scroll_lines, 0);
!     if (n == SPI_SETNONCLIENTMETRICS)
!       set_tabline_font();
      return 0;
  }
  
--- 4291,4314 ----
   * Invoked when a setting was changed.
   */
      static LRESULT CALLBACK
! _OnSettingChange(UINT param)
  {
!     switch (param)
!     {
!       case SPI_SETWHEELSCROLLLINES:
!           SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
!                   &mouse_scroll_lines, 0);
!           break;
!       case SPI_GETWHEELSCROLLCHARS:
!           SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0,
!                   &mouse_scroll_chars, 0);
!           break;
!       case SPI_SETNONCLIENTMETRICS:
!           set_tabline_font();
!           break;
!       default:
!           break;
!     }
      return 0;
  }
  
***************
*** 4723,4729 ****
        return _DuringSizing((UINT)wParam, (LPRECT)lParam);
  
      case WM_MOUSEWHEEL:
!       _OnMouseWheel(hwnd, HIWORD(wParam));
        return 0L;
  
        // Notification for change in SystemParametersInfo()
--- 4770,4777 ----
        return _DuringSizing((UINT)wParam, (LPRECT)lParam);
  
      case WM_MOUSEWHEEL:
!     case WM_MOUSEHWHEEL:
!       _OnMouseWheel(hwnd, HIWORD(wParam), lParam, uMsg == WM_MOUSEHWHEEL);
        return 0L;
  
        // Notification for change in SystemParametersInfo()
*** ../vim-8.2.4873/src/version.c       2022-05-05 17:02:41.498034098 +0100
--- src/version.c       2022-05-05 19:17:16.992073059 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4874,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
103. When you find yourself in the "Computer" section of Barnes & Noble
     enjoying yourself.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220505182336.B72501C0D3D%40moolenaar.net.

Raspunde prin e-mail lui