This commit was generated by cvs2svn to compensate for changes in r4995,
[chise/xemacs-chise.git-] / src / scrollbar-msw.c
index 4f5a0fd..d323d9a 100644 (file)
@@ -24,7 +24,6 @@ Boston, MA 02111-1307, USA.  */
 /* Synched up with: Not in FSF. */
 
 #include <config.h>
-#include <limits.h>
 #include "lisp.h"
 
 #include "console-msw.h"
@@ -48,14 +47,14 @@ mswindows_create_scrollbar_instance (struct frame *f, int vertical,
                                     struct scrollbar_instance *sb)
 {
   int orientation;
-  
+
   sb->scrollbar_data = xnew_and_zero (struct mswindows_scrollbar_data);
-  
+
   if (vertical)
     orientation = SBS_VERT;
   else
     orientation = SBS_HORZ;
-  
+
   SCROLLBAR_MSW_HANDLE (sb) =
     CreateWindowEx(0, "SCROLLBAR", 0, orientation|WS_CHILD,
                 CW_USEDEFAULT, CW_USEDEFAULT,
@@ -84,7 +83,7 @@ static void
 mswindows_free_scrollbar_instance (struct scrollbar_instance *sb)
 {
   DestroyWindow (SCROLLBAR_MSW_HANDLE (sb));
-  if (sb->scrollbar_data) 
+  if (sb->scrollbar_data)
     xfree (sb->scrollbar_data);
 }
 
@@ -147,7 +146,7 @@ mswindows_update_scrollbar_instance_values (struct window *w,
   UPDATE_POS_FIELD (scrollbar_width);
   UPDATE_POS_FIELD (scrollbar_height);
 
-  if (pos_changed) 
+  if (pos_changed)
     {
       MoveWindow(SCROLLBAR_MSW_HANDLE (sb),
                 new_scrollbar_x, new_scrollbar_y,
@@ -187,7 +186,7 @@ mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
   f = XFRAME (frame);
 
   /* SB_LINEDOWN == SB_CHARLEFT etc. This is the way they will
-     always be - any Windows is binary compatible backward with 
+     always be - any Windows is binary compatible backward with
      old programs */
 
   switch (code)
@@ -196,12 +195,12 @@ mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
       mswindows_enqueue_misc_user_event
        (frame, vert ? Qscrollbar_line_down : Qscrollbar_char_right, win);
       break;
-         
+
     case SB_LINEUP:
       mswindows_enqueue_misc_user_event
        (frame, vert ? Qscrollbar_line_up : Qscrollbar_char_left, win);
       break;
-         
+
     case SB_PAGEDOWN:
       mswindows_enqueue_misc_user_event
        (win, vert ? Qscrollbar_page_down : Qscrollbar_page_right,
@@ -214,7 +213,7 @@ mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
         vert ? Qscrollbar_page_up : Qscrollbar_page_left,
         vert ? Fcons (win, Qnil) : win);
       break;
-         
+
     case SB_BOTTOM:
       mswindows_enqueue_misc_user_event
        (frame, vert ? Qscrollbar_to_bottom : Qscrollbar_to_right, win);
@@ -267,7 +266,7 @@ mswindows_handle_scrollbar_event (HWND hwnd, int code, int pos)
 }
 
 static int
-can_scroll(struct scrollbar_instance* scrollbar)
+can_scroll (struct scrollbar_instance* scrollbar)
 {
   return scrollbar != NULL
        && IsWindowVisible (SCROLLBAR_MSW_HANDLE (scrollbar))
@@ -275,15 +274,48 @@ can_scroll(struct scrollbar_instance* scrollbar)
 }
 
 int
-mswindows_handle_mousewheel_event (Lisp_Object frame, int keys, int delta)
+mswindows_handle_mousewheel_event (Lisp_Object frame, int keys, int delta,
+                                  POINTS where)
 {
-  int hasVertBar, hasHorzBar;  /* Indicates prescence of scroll bars */
+  int hasVertBar, hasHorzBar;  /* Indicates presence of scroll bars */
   unsigned wheelScrollLines = 0; /* Number of lines per wheel notch */
+  Lisp_Object win;
+  struct window_mirror *mirror;
+  POINT donde_esta;
+
+  donde_esta.x = where.x;
+  donde_esta.y = where.y;
+
+  ScreenToClient (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), &donde_esta);
 
-  /* Find the currently selected window */
-  Lisp_Object win = FRAME_SELECTED_WINDOW (XFRAME (frame));
-  struct window* w = XWINDOW (win);
-  struct window_mirror* mirror = find_window_mirror (w);
+  /* Find the window to scroll */
+  {
+    int mene, _mene, tekel, upharsin;
+    Bufpos mens, sana;
+    Charcount in;
+    Lisp_Object corpore, sano;
+    struct window *needle_in_haystack;
+
+    // stderr_out ("donde_esta: %d %d\n", donde_esta.x, donde_esta.y);
+    pixel_to_glyph_translation (XFRAME (frame), donde_esta.x, donde_esta.y,
+                               &mene, &_mene, &tekel, &upharsin,
+                               &needle_in_haystack,
+                               &mens, &sana, &in, &corpore, &sano);
+
+    if (needle_in_haystack)
+      {
+       XSETWINDOW (win, needle_in_haystack);
+       // stderr_out ("found needle\n");
+       // debug_print (win);
+      }
+    else
+      {
+       win = FRAME_SELECTED_WINDOW (XFRAME (frame));
+       needle_in_haystack = XWINDOW (win);
+      }
+
+    mirror = find_window_mirror (needle_in_haystack);
+  }
 
   /* Check that there is something to scroll */
   hasVertBar = can_scroll (mirror->scrollbar_vertical_instance);