X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/598d8cacefaa185a962ebc39d31533410692c56b..f4bd67593eae8df6e9a9eb0b7e1374833dbc2a70:/src/os2/window.cpp?ds=sidebyside diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 0e3bf3063f..42c6c75783 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -138,10 +138,14 @@ MRESULT EXPENTRY wxWndProc( HWND hWnd const char *wxGetMessageName(int message); #endif //__WXDEBUG__ -void wxRemoveHandleAssociation(wxWindowOS2* pWin); -void wxAssociateWinWithHandle( HWND hWnd - ,wxWindowOS2* pWin - ); +wxWindowOS2* FindWindowForMouseEvent( wxWindow* pWin + ,short* pnX + ,short* pnY + ); +void wxRemoveHandleAssociation(wxWindowOS2* pWin); +void wxAssociateWinWithHandle( HWND hWnd + ,wxWindowOS2* pWin + ); wxWindow* wxFindWinFromHandle(WXHWND hWnd); // @@ -465,6 +469,14 @@ void wxWindowOS2::SetFocus() ::WinSetFocus(HWND_DESKTOP, hWnd); } // end of wxWindowOS2::SetFocus +void wxWindowOS2::SetFocusFromKbd() +{ + // + // Nothing else to do under OS/2 + // + wxWindowBase::SetFocusFromKbd(); +} // end of wxWindowOS2::SetFocus + wxWindow* wxWindowBase::FindFocus() { HWND hWnd = ::WinQueryFocus(HWND_DESKTOP); @@ -2649,12 +2661,38 @@ MRESULT wxWindowOS2::OS2WindowProc( case WM_BUTTON3MOTIONEND: case WM_BUTTON3MOTIONSTART: { - short x = LOWORD(wParam); - short y = HIWORD(wParam); + if (uMsg == WM_BUTTON1DOWN && AcceptsFocus()) + SetFocus(); + + short nX = LOWORD(wParam); + short nY = HIWORD(wParam); - bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam); + // + // Redirect the event to a static control if necessary + // + if (this == GetCapture()) + { + bProcessed = HandleMouseEvent( uMsg + ,nX + ,nY + ,(WXUINT)SHORT1FROMMP(wParam) + ); + } + else + { + wxWindow* pWin = FindWindowForMouseEvent( this + ,&nX + ,&nY + ); + bProcessed = pWin->HandleMouseEvent( uMsg + ,nX + ,nY + ,(WXUINT)SHORT1FROMMP(wParam) + ); + } } break; + case WM_SYSCOMMAND: bProcessed = HandleSysCommand(wParam, lParam); break; @@ -5101,3 +5139,59 @@ wxPoint wxGetMousePosition() return wxPoint(vPt.x, vPt.y); } +wxWindowOS2* FindWindowForMouseEvent( + wxWindow* pWin +, short* pnX +, short* pnY +) +{ + wxCHECK_MSG( pnX && pnY, pWin, _T("NULL pointer in FindWindowForMouseEvent") ); + POINTL vPoint = { *pnX, *pnY }; + HWND hWnd = GetHwndOf(pWin); + HWND hWndUnderMouse; + + // + // First try to find a non transparent child: this allows us to send events + // to a static text which is inside a static box, for example + // + + hWndUnderMouse = ::WinWindowFromPoint( hWnd + ,&vPoint + ,TRUE + ); + if (!hWndUnderMouse || hWndUnderMouse == hWnd) + { + // + // Now try any child window at all + // + hWndUnderMouse = ::WinWindowFromPoint( HWND_DESKTOP + ,&vPoint + ,TRUE + ); + + } + + // + // Check that we have a child window which is susceptible to receive mouse + // events: for this it must be shown and enabled + if ( hWndUnderMouse && + hWndUnderMouse != hWnd && + ::WinIsWindowVisible(hWndUnderMouse) && + ::WinIsWindowEnabled(hWndUnderMouse)) + { + wxWindow* pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse); + if (pWinUnderMouse) + { + // translate the mouse coords to the other window coords + pWin->ClientToScreen( (int*)pnX + ,(int*)pnY + ); + pWinUnderMouse->ScreenToClient( (int*)pnX + ,(int*)pnY + ); + pWin = pWinUnderMouse; + } + } + return pWin; +} // end of FindWindowForMouseEvent +