X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/51c1d535fc3314e5de95fc4472f4a7e27a2ebeb6..c3d62ecf557627785a4193928fe529f657016932:/src/os2/frame.cpp diff --git a/src/os2/frame.cpp b/src/os2/frame.cpp index 26b4572eec..dbc1e6be98 100644 --- a/src/os2/frame.cpp +++ b/src/os2/frame.cpp @@ -55,7 +55,9 @@ extern wxList WXDLLEXPORT wxPendingDelete; extern wxChar wxFrameClassName[]; extern wxMenu *wxCurrentPopupMenu; -extern void wxAssociateWinWithHandle( HWND hWnd,wxWindow* pWin); +extern void wxAssociateWinWithHandle( HWND hWnd + ,wxWindow* pWin + ); // ---------------------------------------------------------------------------- // event tables @@ -241,6 +243,13 @@ void wxFrame::DoGetClientSize( { RECTL vRect; ::WinQueryWindowRect(GetHwnd(), &vRect); + + // + // No need to use statusbar code as in WIN32 as the FORMATFRAME + // window procedure ensures PM knows about the new frame client + // size internally. A ::WinQueryWindowRect is all that is needed! + // + if (pX) *pX = vRect.xRight - vRect.xLeft; if (pY) @@ -630,7 +639,7 @@ void wxFrame::InternalSetMenuBar() sError = wxPMErrorToStr(vError); wxLogError("Error setting parent for submenu. Error: %s\n", sError); } - WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); + ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); } // end of wxFrame::InternalSetMenuBar // @@ -706,9 +715,9 @@ bool wxFrame::ShowFullScreen( if (lStyle & wxFULLSCREEN_NOMENUBAR) { - ::WinSetParent(m_hMenu, GetHWND(), FALSE); - ::WinSetOwner(m_hMenu, GetHWND()); - ::WinSendMsg((HWND)GetHWND(), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); + ::WinSetParent(m_hMenu, m_hFrame, FALSE); + ::WinSetOwner(m_hMenu, m_hFrame); + ::WinSendMsg((HWND)m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); } #if wxUSE_STATUSBAR @@ -732,16 +741,16 @@ bool wxFrame::ShowFullScreen( // // Save the 'normal' window style // - m_lFsOldWindowStyle = ::WinQueryWindowULong((HWND)GetHWND(), QWL_STYLE); + m_lFsOldWindowStyle = ::WinQueryWindowULong(m_hFrame, QWL_STYLE); // - // Save the old position, width & height, maximize state + // Save the old position, width & height, maximize state // m_vFsOldSize = GetRect(); m_bFsIsMaximized = IsMaximized(); // - // Decide which window style flags to turn off + // Decide which window style flags to turn off // LONG lNewStyle = m_lFsOldWindowStyle; LONG lOffFlags = 0; @@ -756,7 +765,7 @@ bool wxFrame::ShowFullScreen( // // Change our window style to be compatible with full-screen mode // - ::WinSetWindowULong((HWND)GetHWND(), QWL_STYLE, (ULONG)lNewStyle); + ::WinSetWindowULong((HWND)m_hFrame, QWL_STYLE, (ULONG)lNewStyle); // // Resize to the size of the desktop @@ -827,13 +836,13 @@ bool wxFrame::ShowFullScreen( if ((m_lFsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) { - ::WinSetParent(m_hMenu, GetHWND(), FALSE); - ::WinSetOwner(m_hMenu, GetHWND()); - ::WinSendMsg((HWND)GetHWND(), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); + ::WinSetParent(m_hMenu, m_hFrame, FALSE); + ::WinSetOwner(m_hMenu, m_hFrame); + ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); } Maximize(m_bFsIsMaximized); - ::WinSetWindowULong( (HWND)GetHWND() + ::WinSetWindowULong( m_hFrame ,QWL_STYLE ,(ULONG)m_lFsOldWindowStyle ); @@ -982,6 +991,22 @@ bool wxFrame::OS2Create( wxAssociateWinWithHandle(m_hWnd, this); wxAssociateWinWithHandle(m_hFrame, this); + m_backgroundColour.Set(wxString("GREY")); + + LONG lColor = (LONG)m_backgroundColour.GetPixel(); + + if (!::WinSetPresParam( m_hWnd + ,PP_BACKGROUNDCOLOR + ,sizeof(LONG) + ,(PVOID)&lColor + )) + { + vError = ::WinGetLastError(vHabmain); + sError = wxPMErrorToStr(vError); + wxLogError("Error creating frame. Error: %s\n", sError); + return FALSE; + } + // // Now need to subclass window. Instead of calling the SubClassWin in wxWindow // we manually subclass here because we don't want to use the main wxWndProc @@ -1012,10 +1037,10 @@ bool wxFrame::OS2Create( // if (!::WinSetWindowPos( m_hWnd ,HWND_TOP - ,nX + 20 - ,nY + 20 - ,nWidth - 60 - ,nHeight - 60 + ,nX // + 20 + ,nY // + 20 + ,nWidth // - 60 + ,nHeight // - 60 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER )) { @@ -1024,20 +1049,6 @@ bool wxFrame::OS2Create( wxLogError("Error sizing client. Error: %s\n", sError); return FALSE; } - -/* - uCtlCount = SHORT1FROMMP(::WinSendMsg(GetHWND(), WM_FORMATFRAME, (MPARAM)vSwp, (MPARAM)vRect)); - for (int i = 0; i < uCtlCount; i++) - { - if (vSwp[i].hwnd == GetHWND()) - memcpy(&m_vSwp, &vSwp[i], sizeof(SWP)); - else if (vSwp[i].hwnd == m_hVScroll) - memcpy(&m_vSwpVScroll, &vSwp[i], sizeof(SWP)); - else if (vSwp[i].hwnd == m_hHScroll) - memcpy(&m_vSwpVScroll, &vSwp[i], sizeof(SWP)); - else if (vSwp[i].hwnd == m_hTitleBar) - memcpy(&m_vSwpTitleBar, &vSwp[i], sizeof(SWP)); - }*/ return TRUE; } // end of wxFrame::OS2Create @@ -1049,27 +1060,51 @@ void wxFrame::OnActivate( wxActivateEvent& rEvent ) { - for (wxWindowList::Node* pNode = GetChildren().GetFirst(); - pNode; - pNode = pNode->GetNext()) + if ( rEvent.GetActive() ) + { + // restore focus to the child which was last focused + wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); + + wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent() + : NULL; + if (!pParent) + { + pParent = this; + } + + wxSetFocusToChild( pParent + ,&m_pWinLastFocused + ); + } + else // deactivating { - // FIXME all this is totally bogus - we need to do the same as wxPanel, - // but how to do it without duplicating the code? + // + // Remember the last focused child if it is our child + // + m_pWinLastFocused = FindFocus(); + + for (wxWindowList::Node* pNode = GetChildren().GetFirst(); + pNode; + pNode = pNode->GetNext()) + { + // FIXME all this is totally bogus - we need to do the same as wxPanel, + // but how to do it without duplicating the code? - // restore focus - wxWindow* pChild = pNode->GetData(); + // restore focus + wxWindow* pChild = pNode->GetData(); - if (!pChild->IsTopLevel() + if (!pChild->IsTopLevel() #if wxUSE_TOOLBAR - && !wxDynamicCast(pChild, wxToolBar) + && !wxDynamicCast(pChild, wxToolBar) #endif // wxUSE_TOOLBAR #if wxUSE_STATUSBAR - && !wxDynamicCast(pChild, wxStatusBar) + && !wxDynamicCast(pChild, wxStatusBar) #endif // wxUSE_STATUSBAR - ) - { - pChild->SetFocus(); - return; + ) + { + pChild->SetFocus(); + return; + } } } } // end of wxFrame::OnActivate @@ -1152,12 +1187,12 @@ void wxFrame::PositionToolBar() } #endif // wxUSE_STATUSBAR - if ( GetToolBar() ) + if ( m_frameToolBar ) { int nToolbarWidth; int nToolbarHeight; - GetToolBar()->GetSize( &nToolbarWidth + m_frameToolBar->GetSize( &nToolbarWidth ,&nToolbarHeight ); @@ -1253,7 +1288,7 @@ bool wxFrame::HandlePaint() HPOINTER hIcon; if (m_icon.Ok()) - hIcon = (HPOINTER)::WinSendMsg(GetHWND(), WM_QUERYICON, 0L, 0L); + hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L); else hIcon = (HPOINTER)m_hDefaultIcon; @@ -1288,7 +1323,7 @@ bool wxFrame::HandlePaint() } else { - return wxWindow::HandlePaint(); + return(wxWindow::HandlePaint()); } } else @@ -1553,13 +1588,6 @@ MRESULT EXPENTRY wxFrameWndProc( // When we get the first message for the HWND we just created, we associate // it with wxWindow stored in wxWndHook // -// if (!pWnd && wxWndHook) -// { -// wxAssociateWinWithHandle(hWnd, wxWndHook); -// pWnd = wxWndHook; -// wxWndHook = NULL; -// pWnd->SetHWND((WXHWND)hWnd); -// } MRESULT rc = (MRESULT)0; bool bProcessed = FALSE; @@ -1575,87 +1603,10 @@ MRESULT EXPENTRY wxFrameWndProc( } else { - switch (ulMsg) - { - case WM_CLOSE: - // - // If we can't close, tell the system that we processed the - // message - otherwise it would close us - // - bProcessed = !pWnd->Close(); - break; - - case WM_PAINT: - { - HPS hPS; - RECTL vRect; - - hPS = WinBeginPaint(hWnd, 0L, &vRect); - WinFillRect(hPS, &vRect, CLR_BLUE /* SYSCLR_WINDOW */); - WinEndPaint(hPS); - rc = FALSE; - break; - } - break; - - case WM_COMMAND: - { - WORD wId; - WORD wCmd; - WXHWND hWnd; - - pWnd->UnpackCommand( (WXWPARAM)wParam - ,(WXLPARAM)lParam - ,&wId - ,&hWnd - ,&wCmd - ); - rc = (MRESULT) pWnd->HandleCommand( wId - ,wCmd - ,(WXHWND)hWnd - ); - } - break; - - case WM_MENUSELECT: - { - WXWORD wItem; - WXWORD wFlags; - WXHMENU hMenu; - - pWnd->UnpackMenuSelect( wParam - ,lParam - ,&wItem - ,&wFlags - ,&hMenu - ); - bProcessed = pWnd->HandleMenuSelect( wItem - ,wFlags - ,hMenu - ); - rc = (MRESULT)TRUE; - } - break; - - case WM_SIZE: - { - SHORT nScxold = SHORT1FROMMP(wParam); // Old horizontal size. - SHORT nScyold = SHORT2FROMMP(wParam); // Old vertical size. - SHORT nScxnew = SHORT1FROMMP(lParam); // New horizontal size. - SHORT nScynew = SHORT2FROMMP(lParam); // New vertical size. - - lParam = MRFROM2SHORT( nScxnew - 20 - ,nScynew - 30 - ); - } - - bProcessed = pWnd->HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); - rc = (MRESULT)FALSE; - break; - - default: - rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); - } + if (pWnd) + rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam); + else + rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); } return rc; } // end of wxFrameWndProc @@ -1679,18 +1630,34 @@ MRESULT wxFrame::OS2WindowProc( bProcessed = !Close(); break; - case WM_COMMAND: + case WM_PAINT: + bProcessed = HandlePaint(); + mRc = (MRESULT)FALSE; + break; + + case WM_ERASEBACKGROUND: + // + // Returning TRUE to requests PM to paint the window background + // in SYSCLR_WINDOW. We capture this here because the PS returned + // in Frames is the PS for the whole frame, which we can't really + // use at all. If you want to paint a different background, do it + // in an OnPaint using a wxPaintDC. + // + mRc = (MRESULT)(TRUE); + break; + + case WM_COMMAND: { WORD wId; WORD wCmd; WXHWND hWnd; UnpackCommand( (WXWPARAM)wParam - ,(WXLPARAM)lParam - ,&wId - ,&hWnd - ,&wCmd - ); + ,(WXLPARAM)lParam + ,&wId + ,&hWnd + ,&wCmd + ); bProcessed = HandleCommand( wId ,wCmd @@ -1719,17 +1686,19 @@ MRESULT wxFrame::OS2WindowProc( } break; - case WM_PAINT: - bProcessed = HandlePaint(); - break; + case WM_SIZE: + { + SHORT nScxold = SHORT1FROMMP(wParam); // Old horizontal size. + SHORT nScyold = SHORT2FROMMP(wParam); // Old vertical size. + SHORT nScxnew = SHORT1FROMMP(lParam); // New horizontal size. + SHORT nScynew = SHORT2FROMMP(lParam); // New vertical size. - case WM_ERASEBACKGROUND: - // - // Return TRUE to request PM to paint the window background - // in SYSCLR_WINDOW. - // - bProcessed = TRUE; - mRc = (MRESULT)(TRUE); + lParam = MRFROM2SHORT( nScxnew - 20 + ,nScynew - 30 + ); + } + bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); + mRc = (MRESULT)FALSE; break; case CM_QUERYDRAGIMAGE: @@ -1744,91 +1713,6 @@ MRESULT wxFrame::OS2WindowProc( bProcessed = mRc != 0; } break; - - case WM_SIZE: - bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); - break; - - case WM_QUERYFRAMECTLCOUNT: - { - USHORT itemCount = SHORT1FROMMR(OS2GetOldWndProc()(GetHWND(), uMessage, wParam, lParam)); -#if wxUSE_STATUSBAR - if(m_frameStatusBar) - ++itemCount; -#endif //wxUSE_STATUSBAR - - bProcessed = TRUE; - mRc = MRFROMSHORT( itemCount ); - } - break; - - case WM_FORMATFRAME: - { - PSWP pSWP = 0; - USHORT usClient = 0; - SWP swp; - USHORT itemCount; - char s[128]; - - itemCount = SHORT1FROMMR(OS2GetOldWndProc()(GetHWND(), uMessage, wParam, lParam)); - pSWP = (PSWP)PVOIDFROMMP( wParam ); - - while(pSWP[usClient].hwnd != WinWindowFromID(GetHWND(), FID_CLIENT) - && usClient < itemCount) - usClient++; - -#if wxUSE_STATUSBAR - if(m_frameStatusBar) - { - int height; - - m_frameStatusBar->GetSize(NULL, &height); - - if(usClient == itemCount) - { - // frame has no client window - // using another method of calculation - RECTL wRectl; - - ::WinQueryWindowRect(GetHWND(), &wRectl); - ::WinMapWindowPoints(GetHWND(), HWND_DESKTOP, (PPOINTL)&wRectl, 2); - ::WinCalcFrameRect(GetHWND(), &wRectl, TRUE); - ::WinMapWindowPoints(HWND_DESKTOP, GetHWND(), (PPOINTL)&wRectl, 2); - - pSWP[itemCount].x = wRectl.xLeft; - pSWP[itemCount].y = wRectl.yBottom; - pSWP[itemCount].cx = wRectl.xRight - wRectl.xLeft - 1; - pSWP[itemCount].cy = height; - pSWP[itemCount].fl = SWP_SIZE | - SWP_MOVE | - SWP_SHOW; - pSWP[itemCount].hwnd = m_frameStatusBar->GetHWND(); - pSWP[itemCount].hwndInsertBehind = HWND_TOP; - ++itemCount; - } - else - { - pSWP[itemCount].x = pSWP[usClient].x; - pSWP[itemCount].y = pSWP[usClient].y; - pSWP[itemCount].cx = pSWP[usClient].cx; - pSWP[itemCount].cy = height; - pSWP[itemCount].fl = SWP_SIZE | - SWP_MOVE | - SWP_SHOW; - pSWP[itemCount].hwnd = m_frameStatusBar->GetHWND(); - pSWP[itemCount].hwndInsertBehind = HWND_TOP; - pSWP[usClient].cy -= height; - pSWP[usClient].y += height; - - ++itemCount; - } - } -#endif //wxUSE_STATUSBAR - - bProcessed = TRUE; - mRc = MRFROMSHORT(itemCount); - } - break; } if (!bProcessed ) @@ -1865,7 +1749,7 @@ void wxFrame::SetClient( pOldClient->Show( FALSE ); ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId()); // to avoid OS/2 bug need to update frame - ::WinSendMsg((HWND)this->GetHWND(), WM_UPDATEFRAME, (MPARAM)~0, 0); + ::WinSendMsg((HWND)this->GetFrame(), WM_UPDATEFRAME, (MPARAM)~0, 0); return; } @@ -1890,11 +1774,11 @@ void wxFrame::SetClient( if( this->IsShown() ) { this->Show(); - ::WinSendMsg(GetHWND(), WM_UPDATEFRAME, (MPARAM)~0, 0); + ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0); } } wxWindow* wxFrame::GetClient() { - return wxFindWinFromHandle((WXHWND)::WinWindowFromID(GetHWND(), FID_CLIENT)); + return wxFindWinFromHandle((WXHWND)::WinWindowFromID(m_hFrame, FID_CLIENT)); }