Index: gdkevents-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkevents-win32.c,v
retrieving revision 1.133
diff -u -p -r1.133 gdkevents-win32.c
--- gdkevents-win32.c	24 May 2004 22:34:55 -0000	1.133
+++ gdkevents-win32.c	8 Jul 2004 19:13:32 -0000
@@ -140,6 +140,7 @@ static GSourceFuncs event_funcs = {
 };
 
 GPollFD event_poll_fd;
+static gint dispatch_count = 0;
 
 static GdkWindow *current_window = NULL;
 static gint current_x, current_y;
@@ -164,6 +165,10 @@ static UINT     resize_timer;
 
 static int debug_indent = 0;
 
+/* Prevent button 2 MOUSE_UP / MOUSE_DOWN events while using mouse wheel */
+static guint32 last_mouse_wheel_time = 0;
+#define GDK_WIN32_NO_MOUSE_WHEEL_CLICK_DELAY 200
+
 static void
 assign_object (gpointer lhsp,
 	       gpointer rhs)
@@ -1754,139 +1759,6 @@ handle_configure_event (MSG       *msg,
     }
 }
 
-static void
-erase_background (GdkWindow *window,
-		  HDC        hdc)
-{
-  HDC bgdc = NULL;
-  HBRUSH hbr = NULL;
-  HPALETTE holdpal = NULL;
-  RECT rect;
-  COLORREF bg;
-  GdkColormap *colormap;
-  GdkColormapPrivateWin32 *colormap_private;
-  int x, y;
-  int x_offset, y_offset;
-  
-  if (((GdkWindowObject *) window)->input_only ||
-      ((GdkWindowObject *) window)->bg_pixmap == GDK_NO_BG ||
-      GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->position_info.no_bg)
-    {
-      return;
-    }
-
-  colormap = gdk_drawable_get_colormap (window);
-
-  if (colormap &&
-      (colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
-       colormap->visual->type == GDK_VISUAL_STATIC_COLOR))
-    {
-      int k;
-	  
-      colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
-
-      if (!(holdpal = SelectPalette (hdc,  colormap_private->hpal, FALSE)))
-        WIN32_GDI_FAILED ("SelectPalette");
-      else if ((k = RealizePalette (hdc)) == GDI_ERROR)
-	WIN32_GDI_FAILED ("RealizePalette");
-      else if (k > 0)
-	GDK_NOTE (COLORMAP, g_print ("erase_background: realized %p: %d colors\n",
-				     colormap_private->hpal, k));
-    }
-  
-  x_offset = y_offset = 0;
-  while (window && ((GdkWindowObject *) window)->bg_pixmap == GDK_PARENT_RELATIVE_BG)
-    {
-      /* If this window should have the same background as the parent,
-       * fetch the parent. (And if the same goes for the parent, fetch
-       * the grandparent, etc.)
-       */
-      x_offset += ((GdkWindowObject *) window)->x;
-      y_offset += ((GdkWindowObject *) window)->y;
-      window = GDK_WINDOW (((GdkWindowObject *) window)->parent);
-    }
-  
-  if (GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->position_info.no_bg)
-    {
-      /* Improves scolling effect, e.g. main buttons of testgtk */
-      return;
-    }
-
-  GetClipBox (hdc, &rect);
-
-  if (((GdkWindowObject *) window)->bg_pixmap == NULL)
-    {
-      bg = _gdk_win32_colormap_color (GDK_DRAWABLE_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->colormap,
-				      ((GdkWindowObject *) window)->bg_color.pixel);
-      
-      if (!(hbr = CreateSolidBrush (bg)))
-	WIN32_GDI_FAILED ("CreateSolidBrush");
-      else if (!FillRect (hdc, &rect, hbr))
-	WIN32_GDI_FAILED ("FillRect");
-      if (hbr != NULL)
-	DeleteObject (hbr);
-    }
-  else if (((GdkWindowObject *) window)->bg_pixmap != GDK_NO_BG)
-    {
-      GdkPixmap *pixmap = ((GdkWindowObject *) window)->bg_pixmap;
-      GdkPixmapImplWin32 *pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl);
-      
-      if (x_offset == 0 && y_offset == 0 &&
-	  pixmap_impl->width <= 8 && pixmap_impl->height <= 8)
-	{
-	  if (!(hbr = CreatePatternBrush (GDK_PIXMAP_HBITMAP (pixmap))))
-	    WIN32_GDI_FAILED ("CreatePatternBrush");
-	  else if (!FillRect (hdc, &rect, hbr))
-	    WIN32_GDI_FAILED ("FillRect");
-	  if (hbr != NULL)
-	    DeleteObject (hbr);
-	}
-      else
-	{
-	  HGDIOBJ oldbitmap;
-
-	  if (!(bgdc = CreateCompatibleDC (hdc)))
-	    {
-	      WIN32_GDI_FAILED ("CreateCompatibleDC");
-	      return;
-	    }
-	  if (!(oldbitmap = SelectObject (bgdc, GDK_PIXMAP_HBITMAP (pixmap))))
-	    {
-	      WIN32_GDI_FAILED ("SelectObject");
-	      DeleteDC (bgdc);
-	      return;
-	    }
-	  x = -x_offset;
-	  while (x < rect.right)
-	    {
-	      if (x + pixmap_impl->width >= rect.left)
-		{
-		  y = -y_offset;
-		  while (y < rect.bottom)
-		    {
-		      if (y + pixmap_impl->height >= rect.top)
-			{
-			  if (!BitBlt (hdc, x, y,
-				       pixmap_impl->width, pixmap_impl->height,
-				       bgdc, 0, 0, SRCCOPY))
-			    {
-			      WIN32_GDI_FAILED ("BitBlt");
-			      SelectObject (bgdc, oldbitmap);
-			      DeleteDC (bgdc);
-			      return;
-			    }
-			}
-		      y += pixmap_impl->height;
-		    }
-		}
-	      x += pixmap_impl->width;
-	    }
-	  SelectObject (bgdc, oldbitmap);
-	  DeleteDC (bgdc);
-	}
-    }
-}
-
 static GdkRegion *
 _gdk_win32_hrgn_to_region (HRGN hrgn)
 {
@@ -1967,42 +1839,28 @@ handle_wm_paint (MSG        *msg,
 			     hdc,
 			     (return_exposes ? " return_exposes" : "")));
 
-  EndPaint (msg->hwnd, &paintstruct);
-
   /* HB: don't generate GDK_EXPOSE events for InputOnly
    * windows -> backing store now works!
    */
   if (((GdkWindowObject *) window)->input_only)
     {
-      DeleteObject (hrgn);
-      return;
+      ; /* do nothing */
     }
 
-  if (!(((GdkWindowObject *) window)->event_mask & GDK_EXPOSURE_MASK))
+  else if (!(((GdkWindowObject *) window)->event_mask & GDK_EXPOSURE_MASK))
     {
       GDK_NOTE (EVENTS, g_print (" (ignored)"));
-      DeleteObject (hrgn);
-      return;
     }
 
-#if 0 /* we need to process exposes even with GDK_NO_BG
-   * Otherwise The GIMP canvas update is broken ....
-   */
-  if (((GdkWindowObject *) window)->bg_pixmap == GDK_NO_BG)
-    break;
-#endif
-
-  if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
+  else if ((paintstruct.rcPaint.right == paintstruct.rcPaint.left) ||
       (paintstruct.rcPaint.bottom == paintstruct.rcPaint.top))
     {
       GDK_NOTE (EVENTS, g_print (" (empty paintstruct, ignored)"));
-      DeleteObject (hrgn);
-      return;
     }
 
-  if (return_exposes)
+  else if (!GDK_WINDOW_DESTROYED (window))
     {
-      if (!GDK_WINDOW_DESTROYED (window))
+      if (return_exposes)
 	{
 	  GList *list = gdk_drawable_get_display (window)->queued_events;
 
@@ -2027,19 +1885,24 @@ handle_wm_paint (MSG        *msg,
 	      list = list->next;
 	    }
 	}
+      else
+        {
+	  update_region = _gdk_win32_hrgn_to_region (hrgn);
 
-      return;
-    }
-
-  update_region = _gdk_win32_hrgn_to_region (hrgn);
-
-  _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
-  gdk_region_offset (update_region, xoffset, yoffset);
+          _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
+	  gdk_region_offset (update_region, xoffset, yoffset);
   
-  _gdk_window_process_expose (window, update_region);
-  gdk_region_destroy (update_region);
+          _gdk_window_process_expose (window, update_region);
+          gdk_region_destroy (update_region);
 
-  DeleteObject (hrgn);
+          if (dispatch_count == 0)
+	    gdk_window_process_updates (window, FALSE);
+	}
+    }
+  
+  /* Clean up */
+  GDI_CALL(EndPaint, (msg->hwnd, &paintstruct));
+  GDI_CALL(DeleteObject, (hrgn));
 }
 
 static void
@@ -2184,6 +2047,7 @@ gdk_event_translate (GdkDisplay *display
   if (msg->message == msh_mousewheel)
     {
       GDK_NOTE (EVENTS, g_print (" (MSH_MOUSEWHEEL)"));
+      last_mouse_wheel_time = GetTickCount();
       
       /* MSG_MOUSEWHEEL is delivered to the foreground window.  Work
        * around that. Also, the position is in screen coordinates, not
@@ -2471,6 +2335,10 @@ gdk_event_translate (GdkDisplay *display
       goto buttondown0;
 
     case WM_MBUTTONDOWN:
+      if (GetTickCount() < last_mouse_wheel_time + GDK_WIN32_NO_MOUSE_WHEEL_CLICK_DELAY) {
+        return_val = FALSE;
+        goto done;
+      }
       button = 2;
       goto buttondown0;
 
@@ -2553,6 +2421,10 @@ gdk_event_translate (GdkDisplay *display
       goto buttonup0;
 
     case WM_MBUTTONUP:
+      if (GetTickCount() < last_mouse_wheel_time + GDK_WIN32_NO_MOUSE_WHEEL_CLICK_DELAY) {
+        return_val = FALSE;
+        goto done;
+      }
       button = 2;
       goto buttonup0;
 
@@ -2852,13 +2724,15 @@ gdk_event_translate (GdkDisplay *display
       if (GDK_WINDOW_DESTROYED (window))
 	break;
 
-      erase_background (window, (HDC) msg->wParam);
       return_val = TRUE;
-      *ret_valp = 1;
+      *ret_valp = 0;
       break;
 
     case WM_PAINT:
       handle_wm_paint (msg, window, FALSE, NULL);
+      
+      return_val = TRUE;
+      *ret_valp = 0;
       break;
 
     case WM_SETCURSOR:
@@ -3394,7 +3268,11 @@ gdk_event_dispatch (GSource     *source,
   if (event)
     {
       if (_gdk_event_func)
-	(*_gdk_event_func) (event, _gdk_event_data);
+	{
+	  dispatch_count++;
+	  (*_gdk_event_func) (event, _gdk_event_data);
+	  dispatch_count--;
+	}
       
       gdk_event_free (event);
     }
Index: gdkwindow-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkwindow-win32.c,v
retrieving revision 1.118
diff -u -p -r1.118 gdkwindow-win32.c
--- gdkwindow-win32.c	8 May 2004 16:25:15 -0000	1.118
+++ gdkwindow-win32.c	8 Jul 2004 19:13:33 -0000
@@ -1336,20 +1336,25 @@ _gdk_windowing_window_clear_area (GdkWin
 
   if (!GDK_WINDOW_DESTROYED (window))
     {
-      HDC hdc;
+      GdkRectangle rect;
 
       if (width == 0)
 	width = impl->width - x;
       if (height == 0)
 	height = impl->height - y;
+
       GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area: %p: "
 			       "%dx%d@+%d+%d\n",
 			       GDK_WINDOW_HWND (window),
 			       width, height, x, y));
-      hdc = GetDC (GDK_WINDOW_HWND (window));
-      IntersectClipRect (hdc, x, y, x + width + 1, y + height + 1);
-      SendMessage (GDK_WINDOW_HWND (window), WM_ERASEBKGND, (WPARAM) hdc, 0);
-      GDI_CALL (ReleaseDC, (GDK_WINDOW_HWND (window), hdc));
+
+      rect.x = x;
+      rect.y = y;
+      rect.width = width;
+      rect.height = height;
+
+      gdk_window_begin_paint_rect (window, &rect);
+      gdk_window_end_paint (window);
     }
 }
 
@@ -1365,7 +1370,13 @@ _gdk_windowing_window_clear_area_e (GdkW
   
   if (!GDK_WINDOW_DESTROYED (window))
     {
+      GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (window)->impl);
       RECT rect;
+
+      if (width == 0)
+	width = impl->width - x;
+      if (height == 0)
+	height = impl->height - y;
 
       GDK_NOTE (MISC, g_print ("_gdk_windowing_window_clear_area_e: %p: "
 			       "%dx%d@+%d+%d\n",
