]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
* Changed "true" to "TRUE" in some file: "true" doesn't exist in BC++ 5
[wxWidgets.git] / src / msw / window.cpp
index 4f8b2a65588c6947095975ffa9589b349a0956dd..1b69d4592709c10e22eb3fe6307b79d2bf9ca7ba 100644 (file)
@@ -79,7 +79,7 @@
 #undef GetClassInfo
 #endif
 
-#define WINDOW_MARGIN 3        // This defines sensitivity of Leave events
+#define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
 
 wxMenu *wxCurrentPopupMenu = NULL;
 extern wxList wxPendingDelete;
@@ -472,11 +472,10 @@ bool wxWindow::Create(wxWindow *parent, const wxWindowID id,
     msflags |= WS_BORDER;
   if (style & wxTHICK_FRAME)
     msflags |= WS_THICKFRAME;
-  // TODO: probably make WS_CLIPCHILDREN this a setting in wx/setup.h,
-  // to reduce flicker with the trade-off that groupboxes must paint in a solid
-  // colour (so your control order must be correct, and you can't easily draw a
-  // transparent group).
-  msflags |= WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
+
+  msflags |= WS_CHILD | WS_VISIBLE;
+  if (style & wxCLIP_CHILDREN)
+    msflags |= WS_CLIPCHILDREN;
 
   bool want3D;
   WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
@@ -819,9 +818,6 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
   HFONT was = 0;
   if (fontToUse && fontToUse->Ok())
   {
-//    fontToUse->UseResource();
-    
-//    fontToUse->RealizeResource();
     if ((fnt=(HFONT) fontToUse->GetResourceHandle()))
       was = SelectObject(dc,fnt) ;
   }
@@ -881,42 +877,11 @@ void wxWindow::Refresh(const bool eraseBack, const wxRectangle *rect)
   }
 }
 
-// TODO: Are these really necessary now?
-/*
-WXHDC wxWindow::GetHDC(void) const
-{
-  wxWindow *nonConst = (wxWindow *)this;
-  if (m_paintHDC)
-    return(m_paintHDC) ;
-  nonConst->m_tempHDC = (WXHDC) ::GetDC((HWND) GetHWND()) ;
-  return(m_tempHDC) ;
-}
-
-void wxWindow::ReleaseHDC(void)
-{
-  // We're within an OnPaint: it'll be released.
-  if (m_paintHDC)
-    return ;
-
-  ::ReleaseDC((HWND) GetHWND(),(HDC) m_tempHDC) ;
-}
-*/
-
 // Hook for new window just as it's being created,
 // when the window isn't yet associated with the handle
 wxWindow *wxWndHook = NULL;
 
-/*
-#if HAVE_SOCKET
-// DDE Interface Handler
-extern "C" {
-  long ddeWindowProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam);
-  void __ddeUnblock(HWND hWnd, WPARAM wParam);
-};
-#endif
-*/
-
-// Main Windows 3 window proc
+// Main window proc
 LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
   wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
@@ -945,12 +910,6 @@ LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
     wnd->m_lastMsg = message;
     wnd->m_lastWParam = wParam;
     wnd->m_lastLParam = lParam;
-/* Don't know why this was here
-    if (message == WM_SETFONT)
-      return 0;
-    else if (message == WM_INITDIALOG)
-      return TRUE;
-*/
   }
   if (wnd)
     return wnd->MSWWindowProc(message, wParam, lParam);
@@ -1024,12 +983,6 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
 
   switch (message)
   {
-/*
-        case WM_SETFONT:
-        {
-          return 0;
-        }
-*/
         case WM_ACTIVATE:
         {
 #ifdef __WIN32__
@@ -1293,10 +1246,9 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
           return MSWOnMeasureItem((int)wParam, (WXMEASUREITEMSTRUCT *)lParam);
           break;
         }
+
         case WM_KEYDOWN:
         {
-//            return Default();
-
             if (wParam == VK_SHIFT)
                return Default();
 
@@ -1312,23 +1264,18 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                }
                        else
                                return Default();
-            break;
         }
         case WM_KEYUP:
         {
-/*
-            if (wParam == VK_SHIFT)
-              wxShiftDown = FALSE;
-            else if (wParam == VK_CONTROL)
-              wxControlDown = FALSE;
-*/
             break;
         }
+        // VZ: WM_KEYUP not processed
         case WM_CHAR: // Always an ASCII character
         {
           MSWOnChar((WORD)wParam, lParam, TRUE);
           break;
         }
+
         case WM_HSCROLL:
         {
 #ifdef __WIN32__
@@ -1544,7 +1491,7 @@ void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
 {
   // adding NULL hWnd is (first) surely a result of an error and
   // (secondly) breaks menu command processing
-  wxCHECK( hWnd != NULL );
+  wxCHECK_RET( hWnd != NULL, "attempt to add a NULL hWnd to window list" );
 
   if ( !wxWinHandleList->Find((long)hWnd) )
     wxWinHandleList->Append((long)hWnd, win);
@@ -1858,7 +1805,7 @@ bool wxWindow::MSWOnDrawItem(const int id, WXDRAWITEMSTRUCT *itemStruct)
     if ( id == 0 ) {    // is it a menu item?
       DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
       wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
-      wxCHECK_RET( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
+      wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
 
       // prepare to call OnDrawItem()
       wxDC dc;
@@ -1891,7 +1838,7 @@ bool wxWindow::MSWOnMeasureItem(const int id, WXMEASUREITEMSTRUCT *itemStruct)
     if ( id == 0 ) {    // is it a menu item?
       MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
       wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
-      wxCHECK_RET( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
+      wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
 
       return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth, 
                                       &pMeasureStruct->itemHeight);
@@ -1989,7 +1936,11 @@ long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
 
 long wxWindow::Default()
 {
-  return this->MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam);
+    // Ignore 'fake' events (perhaps generated as a result of a separate real event)
+    if (m_lastMsg == 0)
+        return 0;
+
+    return this->MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam);
 }
 
 bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
@@ -2050,51 +2001,6 @@ bool wxWindow::MSWOnPaint(void)
   GetEventHandler()->ProcessEvent(event);
 #endif
   return TRUE;
-  
-#if 0
-
-#if DEBUG > 1
-  wxDebugMsg("wxWindow::MSWOnPaint %d\n", m_hWnd);
-#endif
-#ifdef __WIN32__
-  HRGN tRgn=CreateRectRgn(0,0,0,0);    //Dummy call to get a handle!
-  if (GetUpdateRgn(m_hWnd, tRgn, FALSE))
-#else
-  RECT tRect;
-  if (GetUpdateRect((HWND) m_hWnd, &tRect, FALSE))
-#endif
-  {
-    PAINTSTRUCT ps;
-    // Hold a pointer to the dc so long as the OnPaint() message
-    // is being processed
-    HDC dc = BeginPaint(m_hWnd, &ps);
-    bool isPanel = IsKindOf(CLASSINFO(wxWindow));
-    m_paintHDC = (WXHDC) dc;
-    RECT updateRect1 = ps.rcPaint;
-       m_updateRect.x = updateRect1.left;
-       m_updateRect.y = updateRect1.top;
-       m_updateRect.width = updateRect1.right - updateRect1.left;
-       m_updateRect.height = updateRect1.bottom - updateRect1.top;
-
-    GetEventHandler()->OldOnPaint();
-
-    m_paintHDC = 0;
-    EndPaint((HWND) m_hWnd, &ps);
-#ifdef __WIN32__
-    DeleteObject(tRgn);
-#endif
-
-    if (isPanel)
-      // Do default processing
-      return FALSE;
-    else
-      return TRUE;
-  }
-#ifdef __WIN32__
-  DeleteObject(tRgn);
-#endif
-  return FALSE;
-#endif
 }
 
 void wxWindow::MSWOnSize(const int w, const int h, const WXUINT WXUNUSED(flag))
@@ -2235,17 +2141,7 @@ void wxWindow::MSWOnLButtonDown(const int x, const int y, const WXUINT flags)
   }
 #endif
 
-//wxDebugMsg("LButtonDown\n") ;
-  wxMouseEvent event(wxEVENT_TYPE_LEFT_DOWN);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_LEFT_DOWN);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2262,17 +2158,7 @@ void wxWindow::MSWOnLButtonDown(const int x, const int y, const WXUINT flags)
 
 void wxWindow::MSWOnLButtonUp(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("LButtonUp\n") ;
-  wxMouseEvent event(wxEVENT_TYPE_LEFT_UP);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_LEFT_UP);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2283,26 +2169,14 @@ void wxWindow::MSWOnLButtonUp(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_LEFT_UP;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_UP;
 
   GetEventHandler()->OldOnMouseEvent(event);
 }
 
 void wxWindow::MSWOnLButtonDClick(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("LButtonDClick\n") ;
-  /* MATTHEW: If dclick not allowed, generate another single-click */
-  wxMouseEvent event(m_doubleClickAllowed ?
-                    wxEVENT_TYPE_LEFT_DCLICK : wxEVENT_TYPE_LEFT_DOWN);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_LEFT_DCLICK);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2313,7 +2187,7 @@ void wxWindow::MSWOnLButtonDClick(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_LEFT_DCLICK;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DCLICK;
 
 //  if (m_doubleClickAllowed)
      GetEventHandler()->OldOnMouseEvent(event);
@@ -2342,17 +2216,7 @@ void wxWindow::MSWOnMButtonDown(const int x, const int y, const WXUINT flags)
   }
 #endif
 
-//wxDebugMsg("MButtonDown\n") ;
-  wxMouseEvent event(wxEVENT_TYPE_MIDDLE_DOWN);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_MIDDLE_DOWN);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2363,23 +2227,14 @@ void wxWindow::MSWOnMButtonDown(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_LEFT_DOWN;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DOWN;
   GetEventHandler()->OldOnMouseEvent(event);
 }
 
 void wxWindow::MSWOnMButtonUp(const int x, const int y, const WXUINT flags)
 {
 //wxDebugMsg("MButtonUp\n") ;
-  wxMouseEvent event(wxEVENT_TYPE_MIDDLE_UP);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_MIDDLE_UP);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2390,25 +2245,13 @@ void wxWindow::MSWOnMButtonUp(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_LEFT_UP;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_UP;
   GetEventHandler()->OldOnMouseEvent(event);
 }
 
 void wxWindow::MSWOnMButtonDClick(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("MButtonDClick\n") ;
-  /* MATTHEW: If dclick not allowed, generate another single-click */
-  wxMouseEvent event((m_doubleClickAllowed) ?
-                    wxEVENT_TYPE_MIDDLE_DCLICK : wxEVENT_TYPE_MIDDLE_DOWN);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_MIDDLE_DCLICK);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2419,7 +2262,7 @@ void wxWindow::MSWOnMButtonDClick(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_LEFT_DCLICK;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DCLICK;
 //  if (m_doubleClickAllowed)
      GetEventHandler()->OldOnMouseEvent(event);
 }
@@ -2447,17 +2290,7 @@ void wxWindow::MSWOnRButtonDown(const int x, const int y, const WXUINT flags)
   }
 #endif
 
-//wxDebugMsg("RButtonDown\n") ;
-  wxMouseEvent event(wxEVENT_TYPE_RIGHT_DOWN);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_RIGHT_DOWN);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2468,23 +2301,13 @@ void wxWindow::MSWOnRButtonDown(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_RIGHT_DOWN;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DOWN;
   GetEventHandler()->OldOnMouseEvent(event);
 }
 
 void wxWindow::MSWOnRButtonUp(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("RButtonUp\n") ;
-  wxMouseEvent event(wxEVENT_TYPE_RIGHT_UP);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_RIGHT_UP);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2495,25 +2318,13 @@ void wxWindow::MSWOnRButtonUp(const int x, const int y, const WXUINT flags)
   event.m_eventObject = this;
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_RIGHT_UP;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_UP;
   GetEventHandler()->OldOnMouseEvent(event);
 }
 
 void wxWindow::MSWOnRButtonDClick(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("RButtonDClick\n") ;
-  /* MATTHEW: If dclick not allowed, generate another single-click */
-  wxMouseEvent event((m_doubleClickAllowed) ?
-                    wxEVENT_TYPE_RIGHT_DCLICK : wxEVENT_TYPE_RIGHT_DOWN);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_RIGHT_DCLICK);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2524,7 +2335,7 @@ void wxWindow::MSWOnRButtonDClick(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVENT_TYPE_RIGHT_DCLICK;
+  m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DCLICK;
 //  if (m_doubleClickAllowed)
      GetEventHandler()->OldOnMouseEvent(event);
 }
@@ -2538,126 +2349,14 @@ void wxWindow::MSWOnMouseMove(const int x, const int y, const WXUINT flags)
   if (m_windowCursor.Ok() && !wxIsBusy())
     ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR());
 
-  wxMouseEvent event(wxEVENT_TYPE_MOTION);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
-
-  event.m_x = x; event.m_y = y;
-  event.m_shiftDown = ((flags & MK_SHIFT) != 0);
-  event.m_controlDown = ((flags & MK_CONTROL) != 0);
-  event.m_leftDown = ((flags & MK_LBUTTON) != 0);
-  event.m_middleDown = ((flags & MK_MBUTTON) != 0);
-  event.m_rightDown = ((flags & MK_RBUTTON) != 0);
-  event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
-  event.m_eventObject = this;
-
-  // Window gets a click down message followed by a mouse move
-  // message even if position isn't changed!  We want to discard
-  // the trailing move event if x and y are the same.
-  if ((m_lastEvent == wxEVENT_TYPE_RIGHT_DOWN || m_lastEvent == wxEVENT_TYPE_LEFT_DOWN ||
-       m_lastEvent == wxEVENT_TYPE_MIDDLE_DOWN) &&
-      (m_lastXPos == event.m_x && m_lastYPos == event.m_y))
+ if (!m_mouseInWindow)
   {
-    m_lastXPos = event.m_x; m_lastYPos = event.m_y;
-    m_lastEvent = wxEVENT_TYPE_MOTION;
-    return;
+    // Generate an ENTER event
+    m_mouseInWindow = TRUE;
+    MSWOnMouseEnter(x, y, flags);
   }
 
-  m_lastEvent = wxEVENT_TYPE_MOTION;
-  m_lastXPos = event.m_x; m_lastYPos = event.m_y;
-  GetEventHandler()->OldOnMouseEvent(event);
-}
-
-/* TODO put back leave/enter code if required
- */
-#if 0
-void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags)
-{
-//wxDebugMsg("Client 0x%08x Move Msg %d,%d\n",this,x,y) ;
-
-// #if MOUSE_EXIT_FIX //Should work now!!
-
-  // Don't do the Leave/Enter fix if we've captured the window,
-  // or SetCapture won't work properly.
-  if (!m_winCaptured)
-  {
-    HWND hunder ;
-    POINT pt ;
-    // See if we Leave/Enter the window.
-    GetCursorPos(&pt) ;
-    hunder = WindowFromPoint(pt) ;
-    if (hunder==m_hWnd)
-    {
-      // I'm in the Window, but perhaps in NC area.
-      RECT wind ;
-      RECT nc ;
-      GetClientRect(m_hWnd,&wind) ;
-      GetWindowRect(m_hWnd,&nc) ;
-      pt.x -= nc.left ;
-      pt.y -= nc.top ;
-      wind.left    += WINDOW_MARGIN ; // to be able to 'see' leave
-      wind.top     += WINDOW_MARGIN ; // to be able to 'see' leave
-      wind.right   -= WINDOW_MARGIN ; // to be able to 'see' leave
-      wind.bottom  -= WINDOW_MARGIN ; // to be able to 'see' leave
-
-      if (!PtInRect(&wind,pt))
-        hunder = NULL ; // So, I can simulate a Leave event...
-    }
-
-    if (hunder!=m_hWnd)
-    {
-      if (m_mouseInWindow)
-      {
-        m_mouseInWindow = FALSE ;
-        // Capture/Release is no more needed...
-        //ReleaseCapture() ;
-        MSWOnMouseLeave(x,y,flags) ;
-        return ;
-      }
-      // We never want to see Enter or Motion in this part of the Window...
-      return ;
-    }
-    else
-    {
-      // Event was triggered while I'm really into my client area.
-      // Do an Enter if not done.
-      if (!m_mouseInWindow)
-      {
-        m_mouseInWindow = TRUE ;
-        // Capture/Release is no more needed...
-        //SetCapture(m_hWnd) ;
-        // Set cursor, but only if we're not in 'busy' mode
-        if (m_windowCursor.Ok() && !wxIsBusy())
-          ::SetCursor(m_windowCursor.ms_cursor);
-        MSWOnMouseEnter(x,y,flags) ;
-        return ;
-      }
-    }
-  }
-// #endif //MOUSE_EXIT_FIX
-    
-  // 'normal' move event...
-  // Set cursor, but only if we're not in 'busy' mode
-  if (m_windowCursor.Ok() && !wxIsBusy())
-    ::SetCursor(m_windowCursor.ms_cursor);
-
-  wxMouseEvent event(wxEVENT_TYPE_MOTION);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_MOTION);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2671,39 +2370,23 @@ void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags)
   // Window gets a click down message followed by a mouse move
   // message even if position isn't changed!  We want to discard
   // the trailing move event if x and y are the same.
-  if ((m_lastEvent == wxEVENT_TYPE_RIGHT_DOWN || m_lastEvent == wxEVENT_TYPE_LEFT_DOWN ||
-       m_lastEvent == wxEVENT_TYPE_MIDDLE_DOWN) &&
+  if ((m_lastEvent == wxEVT_RIGHT_DOWN || m_lastEvent == wxEVT_LEFT_DOWN ||
+       m_lastEvent == wxEVT_MIDDLE_DOWN) &&
       (m_lastXPos == event.m_x && m_lastYPos == event.m_y))
   {
     m_lastXPos = event.m_x; m_lastYPos = event.m_y;
-    m_lastEvent = wxEVENT_TYPE_MOTION;
+    m_lastEvent = wxEVT_MOTION;
     return;
   }
 
-  m_lastEvent = wxEVENT_TYPE_MOTION;
+  m_lastEvent = wxEVT_MOTION;
   m_lastXPos = event.m_x; m_lastYPos = event.m_y;
   GetEventHandler()->OldOnMouseEvent(event);
 }
-#endif
 
 void wxWindow::MSWOnMouseEnter(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("Client 0x%08x Enter %d,%d\n",this,x,y) ;
-
-  // Set cursor, but only if we're not in 'busy' mode
-  if (m_windowCursor.Ok() && !wxIsBusy())
-    ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR());
-
-  wxMouseEvent event(wxEVENT_TYPE_ENTER_WINDOW);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_ENTER_WINDOW);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2714,29 +2397,16 @@ void wxWindow::MSWOnMouseEnter(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastEvent = wxEVENT_TYPE_ENTER_WINDOW;
+  m_lastEvent = wxEVT_ENTER_WINDOW;
   m_lastXPos = event.m_x; m_lastYPos = event.m_y;
-  GetEventHandler()->OldOnMouseEvent(event);
+  // No message - ensure we don't try to call the default behaviour accidentally.
+  m_lastMsg = 0;
+  GetEventHandler()->ProcessEvent(event);
 }
 
 void wxWindow::MSWOnMouseLeave(const int x, const int y, const WXUINT flags)
 {
-//wxDebugMsg("Client 0x%08x Leave %d,%d\n",this,x,y) ;
-
-  // Set cursor, but only if we're not in 'busy' mode
-  if (m_windowCursor.Ok() && !wxIsBusy())
-    ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR());
-
-  wxMouseEvent event(wxEVENT_TYPE_LEAVE_WINDOW);
-
-/*
-  float px = (float)x;
-  float py = (float)y;
-
-  MSWDeviceToLogical(&px, &py);
-
-  CalcUnscrolledPosition((int)px, (int)py, &event.m_x, &event.m_y);
-*/
+  wxMouseEvent event(wxEVT_LEAVE_WINDOW);
 
   event.m_x = x; event.m_y = y;
   event.m_shiftDown = ((flags & MK_SHIFT) != 0);
@@ -2747,9 +2417,11 @@ void wxWindow::MSWOnMouseLeave(const int x, const int y, const WXUINT flags)
   event.SetTimestamp(wxApp::sm_lastMessageTime); /* MATTHEW: timeStamp */
   event.m_eventObject = this;
 
-  m_lastEvent = wxEVENT_TYPE_LEAVE_WINDOW;
+  m_lastEvent = wxEVT_LEAVE_WINDOW;
   m_lastXPos = event.m_x; m_lastYPos = event.m_y;
-  GetEventHandler()->OldOnMouseEvent(event);
+  // No message - ensure we don't try to call the default behaviour accidentally.
+  m_lastMsg = 0;
+  GetEventHandler()->ProcessEvent(event);
 }
 
 void wxWindow::MSWOnChar(const WXWORD wParam, const WXLPARAM lParam, const bool isASCII)
@@ -2787,11 +2459,13 @@ void wxWindow::MSWOnChar(const WXWORD wParam, const WXLPARAM lParam, const bool
       }
     }
   }
-  else
-    if ((id = wxCharCodeMSWToWX(wParam)) == 0)
+  else if ((id = wxCharCodeMSWToWX(wParam)) == 0) {
+      // it's ASCII and will be processed here only when called from
+      // WM_CHAR (i.e. when isASCII = TRUE)
       id = -1;
+  }
 
-  if (id > -1)
+  if (id != -1)
   {
     wxKeyEvent event(wxEVT_CHAR);
     event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
@@ -2810,13 +2484,6 @@ void wxWindow::MSWOnChar(const WXWORD wParam, const WXLPARAM lParam, const bool
     pt.x -= rect.left ;
     pt.y -= rect.top ;
 
-/*
-    float fx,fy ;
-    fx = (float)pt.x ;
-    fy = (float)pt.y ;
-    MSWDeviceToLogical(&fx,&fy) ;
-    CalcUnscrolledPosition((int)fx,(int)fy,&event.m_x,&event.m_y) ;
-*/
     event.m_x = pt.x; event.m_y = pt.y;
 
 #if WXWIN_COMPATIBILITY
@@ -2942,32 +2609,32 @@ void wxWindow::MSWOnVScroll(const WXWORD wParam, const WXWORD pos, const WXHWND
        switch ( wParam )
        {
                case SB_TOP:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_TOP;
+                       event.m_eventType = wxEVT_SCROLL_TOP;
                        break;
 
                case SB_BOTTOM:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_BOTTOM;
+                       event.m_eventType = wxEVT_SCROLL_BOTTOM;
                        break;
 
                case SB_LINEUP:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_LINEUP;
+                       event.m_eventType = wxEVT_SCROLL_LINEUP;
                        break;
 
                case SB_LINEDOWN:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_LINEDOWN;
+                       event.m_eventType = wxEVT_SCROLL_LINEDOWN;
                        break;
 
                case SB_PAGEUP:
-                        event.m_eventType = wxEVENT_TYPE_SCROLL_PAGEUP;
+                        event.m_eventType = wxEVT_SCROLL_PAGEUP;
                        break;
 
                case SB_PAGEDOWN:
-                        event.m_eventType = wxEVENT_TYPE_SCROLL_PAGEDOWN;
+                        event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
                        break;
 
         case SB_THUMBTRACK:
         case SB_THUMBPOSITION:
-                        event.m_eventType = wxEVENT_TYPE_SCROLL_THUMBTRACK;
+                        event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
                        break;
 
                default:
@@ -3001,32 +2668,32 @@ void wxWindow::MSWOnHScroll( const WXWORD wParam, const WXWORD pos, const WXHWND
        switch ( wParam )
        {
                case SB_TOP:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_TOP;
+                       event.m_eventType = wxEVT_SCROLL_TOP;
                        break;
 
                case SB_BOTTOM:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_BOTTOM;
+                       event.m_eventType = wxEVT_SCROLL_BOTTOM;
                        break;
 
                case SB_LINEUP:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_LINEUP;
+                       event.m_eventType = wxEVT_SCROLL_LINEUP;
                        break;
 
                case SB_LINEDOWN:
-                       event.m_eventType = wxEVENT_TYPE_SCROLL_LINEDOWN;
+                       event.m_eventType = wxEVT_SCROLL_LINEDOWN;
                        break;
 
                case SB_PAGEUP:
-                        event.m_eventType = wxEVENT_TYPE_SCROLL_PAGEUP;
+                        event.m_eventType = wxEVT_SCROLL_PAGEUP;
                        break;
 
                case SB_PAGEDOWN:
-                        event.m_eventType = wxEVENT_TYPE_SCROLL_PAGEDOWN;
+                        event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
                        break;
 
         case SB_THUMBTRACK:
         case SB_THUMBPOSITION:
-                        event.m_eventType = wxEVENT_TYPE_SCROLL_THUMBTRACK;
+                        event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
                        break;
 
                default:
@@ -4701,7 +4368,7 @@ void wxWindow::OnDefaultAction(wxControl *initiatingItem)
   if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)) && initiatingItem->GetCallback())
   {
     wxListBox *lbox = (wxListBox *)initiatingItem;
-    wxCommandEvent event(wxEVENT_TYPE_LISTBOX_DCLICK_COMMAND);
+    wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
     event.m_commandInt = -1;
     if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
     {
@@ -4721,7 +4388,7 @@ void wxWindow::OnDefaultAction(wxControl *initiatingItem)
   wxButton *but = GetDefaultItem();
   if (but)
   {
-    wxCommandEvent event(wxEVENT_TYPE_BUTTON_COMMAND);
+    wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
     but->Command(event);
   }
 }
@@ -4950,6 +4617,18 @@ void wxWindow::UpdateWindowUI(void)
 
 void wxWindow::OnIdle(wxIdleEvent& event)
 {
+    // Check if we need to send a LEAVE event
+    if (m_mouseInWindow)
+    {
+        POINT pt;
+        ::GetCursorPos(&pt);
+        if (::WindowFromPoint(pt) != (HWND) GetHWND())
+        {
+            // Generate a LEAVE event
+            m_mouseInWindow = FALSE;
+            MSWOnMouseLeave(pt.x, pt.y, 0);
+        }
+    }
        UpdateWindowUI();
 }