X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40bd6154f1476dbe598c60b4760bbf2fe0d9ab0f..eedb15434a5f0350f4e1a11faaab3391b900cb5b:/src/os2/window.cpp diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 6073949ccb..c1ea3d7068 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -153,6 +153,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxWindowBase) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) + EVT_SET_FOCUS(wxWindow::OnSetFocus) END_EVENT_TABLE() // =========================================================================== @@ -306,6 +307,7 @@ wxWindow::~wxWindow() if (m_parent) m_parent->RemoveChild(this); DestroyChildren(); + if (m_hWnd) { if(!::WinDestroyWindow(GetHWND())) @@ -356,6 +358,12 @@ bool wxWindow::Create( // set in those class create procs. PM's basic windows styles are // very limited. // + ulCreateFlags |= WS_VISIBLE; + + + if ( lStyle & wxCLIP_SIBLINGS ) + ulCreateFlags |= WS_CLIPSIBLINGS; + if (lStyle & wxCLIP_CHILDREN ) ulCreateFlags |= WS_CLIPCHILDREN; @@ -382,6 +390,7 @@ bool wxWindow::Create( ,NULLHANDLE ,m_windowId ); + return(TRUE); } // end of wxWindow::Create @@ -711,31 +720,23 @@ void wxWindow::SubclassWin( HWND hwnd = (HWND)hWnd; wxASSERT_MSG( !m_fnOldWndProc, wxT("subclassing window twice?") ); - wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") ); - - wxAssociateWinWithHandle(hwnd, this); - m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc); - ::WinSetWindowULong(hwnd, QWS_USER, (ULONG)wxWndProc); } // end of wxWindow::SubclassWin void wxWindow::UnsubclassWin() { - wxRemoveHandleAssociation(this); - // // Restore old Window proc // - HWND hwnd = GetHwnd(); + HWND hwnd = GetHWND(); - if (hwnd) + if (m_hWnd) { - m_hWnd = 0; - wxCHECK_RET( ::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in UnsubclassWin") ); - PFNWP fnProc = (PFNWP)::WinQueryWindowULong(hwnd, QWS_USER); + PFNWP fnProc = (PFNWP)::WinQueryWindowPtr(hwnd, QWP_PFNWP); + if ( (m_fnOldWndProc != 0) && (fnProc != (PFNWP) m_fnOldWndProc)) { WinSubclassWindow(hwnd, (PFNWP)m_fnOldWndProc); @@ -1096,7 +1097,10 @@ void wxWindow::DoGetClientSize( RECTL vRect; hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); - ::WinQueryWindowRect(hWndClient, &vRect); + if( hWndClient == NULLHANDLE) + ::WinQueryWindowRect(GetHwnd(), &vRect); + else + ::WinQueryWindowRect(hWndClient, &vRect); if (pWidth) *pWidth = vRect.xRight; @@ -1320,10 +1324,12 @@ int wxWindow::GetCharHeight() const hPs = ::WinGetPS(GetHwnd()); if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics)) + { + ::WinReleasePS(hPs); return (0); - else - return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender); + } ::WinReleasePS(hPs); + return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender); } // end of wxWindow::GetCharHeight int wxWindow::GetCharWidth() const @@ -1334,10 +1340,12 @@ int wxWindow::GetCharWidth() const hPs = ::WinGetPS(GetHwnd()); if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics)) + { + ::WinReleasePS(hPs); return (0); - else - return(vFontMetrics.lAveCharWidth); + } ::WinReleasePS(hPs); + return(vFontMetrics.lAveCharWidth); } // end of wxWindow::GetCharWidth void wxWindow::GetTextExtent( @@ -1502,9 +1510,9 @@ MRESULT wxWindow::OS2DefWindowProc( ) { if (m_fnOldWndProc) - return ((MRESULT)m_fnOldWndProc()); + return (MRESULT)m_fnOldWndProc(GetHWND(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam); else - return (::WinDefWindowProc(GetHwnd(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam)); + return ::WinDefWindowProc(GetHWND(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam); } // end of wxWindow::OS2DefWindowProc bool wxWindow::OS2ProcessMessage( @@ -1699,7 +1707,11 @@ bool wxWindow::OS2TranslateMessage( WXMSG* pMsg ) { - return m_acceleratorTable.Translate(this, pMsg); +#if wxUSE_ACCEL + return m_acceleratorTable.Translate(m_hWnd, pMsg); +#else + return FALSE; +#endif //wxUSE_ACCEL } // end of wxWindow::OS2TranslateMessage // --------------------------------------------------------------------------- @@ -1715,8 +1727,8 @@ void wxWindow::UnpackCommand( ) { *pId = LOWORD(wParam); - *phWnd = (WXHWND)lParam; - *pCmd = HIWORD(wParam); + *phWnd = NULL; // or may be GetHWND() ? + *pCmd = LOWORD(lParam); } // end of wxWindow::UnpackCommand void wxWindow::UnpackActivate( @@ -1798,7 +1810,8 @@ MRESULT EXPENTRY wxWndProc( pWnd->SetHWND((WXHWND)hWnd); } - MRESULT rc; + MRESULT rc = (MRESULT)0; + // // Stop right here if we don't have a valid handle in our wxWindow object. @@ -1816,6 +1829,7 @@ MRESULT EXPENTRY wxWndProc( else rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); } + return rc; } // end of wxWndProc @@ -1833,22 +1847,15 @@ MRESULT wxWindow::OS2WindowProc( // Did we process the uMsg? // bool bProcessed = FALSE; - - // - // The return value - // - union - { - bool bAllow; - MRESULT mResult; - WXHICON hIcon; - WXHBRUSH hBrush; - } vRc; + bool bAllow; + MRESULT mResult; + WXHICON hIcon; + WXHBRUSH hBrush; // // For most messages we should return 0 when we do process the message // - vRc.mResult = (MRESULT)0; + mResult = (MRESULT)0; switch (uMsg) { @@ -1864,14 +1871,15 @@ MRESULT wxWindow::OS2WindowProc( // // Return 0 to bAllow window creation // - vRc.mResult = (MRESULT)(bMayCreate ? 0 : -1); + mResult = (MRESULT)(bMayCreate ? 0 : -1); } } break; case WM_DESTROY: - bProcessed = HandleDestroy(); - break; + HandleDestroy(); + bProcessed = TRUE; + break; case WM_MOVE: bProcessed = HandleMove( LOWORD(lParam) @@ -1900,6 +1908,7 @@ MRESULT wxWindow::OS2WindowProc( bProcessed = HandleActivate( wState ,(WXHWND)hWnd ); + bProcessed = FALSE; } break; @@ -1920,7 +1929,7 @@ MRESULT wxWindow::OS2WindowProc( // ourselves in ~wxWindow // bProcessed = TRUE; - vRc.mResult = (MRESULT)TRUE; + mResult = (MRESULT)TRUE; break; case WM_SHOW: @@ -1954,7 +1963,6 @@ MRESULT wxWindow::OS2WindowProc( bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam); } break; - case WM_SYSCOMMAND: bProcessed = HandleSysCommand(wParam, lParam); break; @@ -1988,14 +1996,14 @@ MRESULT wxWindow::OS2WindowProc( } if ( bProcessed ) - vRc.mResult = (MRESULT)TRUE; + mResult = (MRESULT)TRUE; } break; case WM_QUERYDLGCODE: if ( m_lDlgCode ) { - vRc.mResult = (MRESULT)m_lDlgCode; + mResult = (MRESULT)m_lDlgCode; bProcessed = TRUE; } // @@ -2094,7 +2102,7 @@ MRESULT wxWindow::OS2WindowProc( #if defined(__VISAGECPP__) && (__IBMCPP__ >= 400) case WM_CTLCOLORCHANGE: { - bProcessed = HandleCtlColor(&vRc.hBrush); + bProcessed = HandleCtlColor(&hBrush); } break; #endif @@ -2133,7 +2141,7 @@ MRESULT wxWindow::OS2WindowProc( // // We processed the message, i.e. erased the background // - vRc.mResult = (MRESULT)TRUE; + mResult = (MRESULT)TRUE; } break; @@ -2148,18 +2156,18 @@ MRESULT wxWindow::OS2WindowProc( if ( bProcessed ) { // we never set focus from here - vRc.mResult = FALSE; + mResult = FALSE; } break; // wxFrame specific message case WM_MINMAXFRAME: - bProcessed = HandleGetMinMaxInfo((PSWP)lParam); + bProcessed = HandleGetMinMaxInfo((PSWP)wParam); break; case WM_SYSVALUECHANGED: // TODO: do something - vRc.mResult = (MRESULT)TRUE; + mResult = (MRESULT)TRUE; break; // @@ -2176,20 +2184,22 @@ MRESULT wxWindow::OS2WindowProc( // processing this message - exactly what we need because we've // just set the cursor. // - vRc.mResult = (MRESULT)TRUE; + mResult = (MRESULT)TRUE; } break; } - if (!bProcessed) { #ifdef __WXDEBUG__ wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."), wxGetMessageName(uMsg)); #endif // __WXDEBUG__ - vRc.mResult = OS2DefWindowProc(uMsg, wParam, lParam); + if (IsKindOf(CLASSINFO(wxFrame))) + mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam); + else + mResult = OS2DefWindowProc(uMsg, wParam, lParam); } - return vRc.mResult; + return mResult; } // end of wxWindow::OS2WindowProc // @@ -2326,11 +2336,13 @@ bool wxWindow::OS2Create( { ERRORID vError; wxString sError; - long lX1 = (long)CW_USEDEFAULT; + long lX1 = 0L; long lY1 = 0L; - long lWidth1 = (long)CW_USEDEFAULT; - long lHeight1 = 100L; + long lWidth1 = 20L; + long lHeight1 = 20L; int nControlId = 0; + int nNeedsubclass = 0; + PCSZ pszClass = zClass; // // Find parent's size, if it exists, to set up a possible default @@ -2370,6 +2382,21 @@ bool wxWindow::OS2Create( { nControlId = ulId; } + else + { + // no standard controls + if(wxString (wxT("wxFrameClass")) == wxString(zClass) ) + { + pszClass = WC_FRAME; + nNeedsubclass = 1; + } + else + { + nControlId = ulId; + if(nControlId < 0) + nControlId = FID_CLIENT; + } + } // // We will either have a registered class via string name or a standard PM Class via a long @@ -2382,9 +2409,9 @@ bool wxWindow::OS2Create( ,(LONG)lY1 ,(LONG)lWidth ,(LONG)lHeight - ,NULLHANDLE + ,hOwner ,HWND_TOP - ,(ULONG)ulId + ,(ULONG)nControlId ,pCtlData ,pPresParams ); @@ -2395,6 +2422,7 @@ bool wxWindow::OS2Create( wxLogError("Can't create window of class %s!. Error: %s\n", zClass, sError); return FALSE; } + ::WinSetWindowULong(m_hWnd, QWL_USER, (ULONG) this); wxWndHook = NULL; #ifdef __WXDEBUG__ @@ -2414,6 +2442,17 @@ bool wxWindow::OS2Create( wxAssociateWinWithHandle((HWND)m_hWnd ,this ); + // + // Now need to subclass window. + // + if(!nNeedsubclass) + { + wxAssociateWinWithHandle((HWND)m_hWnd,this); + } + else + { + SubclassWin(GetHWND()); + } return TRUE; } // end of wxWindow::OS2Create @@ -2805,12 +2844,21 @@ bool wxWindow::HandlePaint() wxLogLastError("CreateRectRgn"); return FALSE; } - m_updateRegion = wxRegion(hRgn); + // + // Debug code + // +#ifdef __WXDEBUG__ + { + HWND hWnd; + HWND hWnd0 = NULLHANDLE; - hPS = WinBeginPaint(GetHwnd(), 0L, &vRect); - WinFillRect(hPS, &vRect, SYSCLR_WINDOW); - WinEndPaint(hPS); + hWnd = GetHwnd(); + if(hWnd != hWnd0) + printf("HandlePaint hWnd=%x ",hWnd); + } +#endif + m_updateRegion = wxRegion(hRgn); vEvent.SetEventObject(this); return (GetEventHandler()->ProcessEvent(vEvent)); } // end of wxWindow::HandlePaint @@ -3950,3 +3998,45 @@ static void TranslateKbdEventToMouse( pWin->ScreenToClient(pX, pY); } // end of TranslateKbdEventToMouse +// Find the wxWindow at the current mouse position, returning the mouse +// position. +wxWindow* wxFindWindowAtPointer( + wxPoint& rPt +) +{ + return wxFindWindowAtPoint(wxGetMousePosition()); +} + +wxWindow* wxFindWindowAtPoint( + const wxPoint& rPt +) +{ + POINTL vPt2; + + vPt2.x = rPt.x; + vPt2.y = rPt.y; + + HWND hWndHit = ::WinWindowFromPoint(HWND_DESKTOP, &vPt2, FALSE); + wxWindow* pWin = wxFindWinFromHandle((WXHWND)hWndHit) ; + HWND hWnd = hWndHit; + + // + // Try to find a window with a wxWindow associated with it + // + while (!pWin && (hWnd != 0)) + { + hWnd = ::WinQueryWindow(hWnd, QW_PARENT); + pWin = wxFindWinFromHandle((WXHWND)hWnd) ; + } + return pWin; +} + +// Get the current mouse position. +wxPoint wxGetMousePosition() +{ + POINTL vPt; + + ::WinQueryPointerPos(HWND_DESKTOP, &vPt); + return wxPoint(vPt.x, vPt.y); +} +