X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c299c3ab663257429983c24e6fb71450f3cf9f1..91b4bd63177025704dd39679a2a7c4198eeb7909:/src/os2/window.cpp diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 2c16e35794..c30bdb8ba4 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -34,7 +34,11 @@ #include "wx/button.h" #include "wx/msgdlg.h" #include "wx/scrolwin.h" - + #include "wx/radiobox.h" + #include "wx/slider.h" + #include "wx/statusbr.h" + #include "wx/toolbar.h" + #include "wx/settings.h" #include #endif @@ -102,9 +106,6 @@ QMSG s_currentMsg; wxMenu* wxCurrentPopupMenu = NULL; #endif // wxUSE_MENUS_NATIVE -#if !defined(__VISAGECPP__) || (__IBMCPP__ < 400) -extern wxChar wxCanvasClassName[]; -#endif wxList* wxWinHandleList = NULL; // --------------------------------------------------------------------------- @@ -147,6 +148,9 @@ static void TranslateKbdEventToMouse( wxWindow* pWin // static inline bool IsShiftDown() { return (::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000) != 0; } static inline bool IsCtrlDown() { return (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000) != 0; } + +static wxWindow* gpWinBeingCreated = NULL; + // --------------------------------------------------------------------------- // event tables // --------------------------------------------------------------------------- @@ -327,7 +331,6 @@ wxWindowOS2::~wxWindowOS2() { m_isBeingDeleted = TRUE; - OS2DetachWindowMenu(); for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent()) { wxFrame* pFrame = wxDynamicCast(pWin, wxFrame); @@ -366,7 +369,6 @@ bool wxWindowOS2::Create( ) { HWND hParent = NULLHANDLE; - wxPoint vPos = rPos; // The OS/2 position ULONG ulCreateFlags = 0; WXDWORD dwExStyle = 0; @@ -439,23 +441,17 @@ bool wxWindowOS2::Create( } // - // Generic OS/2 Windows are created with no owner, no Z Order, no Control data, - // and no presentation parameters + // Generic OS/2 Windows have no Control Data but other classes + // that call OS2Create may have some. // - OS2Create( hParent - ,(PSZ)wxCanvasClassName + OS2Create( (PSZ)wxCanvasClassName ,rName.c_str() ,ulCreateFlags - ,vPos.x - ,vPos.y - ,WidthDefault(rSize.x) - ,HeightDefault(rSize.y) - ,NULLHANDLE - ,NULLHANDLE - ,m_windowId - ,NULL - ,NULL + ,rPos + ,rSize + ,NULL // Control Data ,dwExStyle + ,TRUE // Child ); return(TRUE); @@ -549,7 +545,7 @@ wxString wxWindowOS2::GetTitle() const return wxGetWindowText(GetHWND()); } // end of wxWindowOS2::GetTitle -void wxWindowOS2::CaptureMouse() +void wxWindowOS2::DoCaptureMouse() { HWND hWnd = GetHwnd(); @@ -560,7 +556,7 @@ void wxWindowOS2::CaptureMouse() } } // end of wxWindowOS2::GetTitle -void wxWindowOS2::ReleaseMouse() +void wxWindowOS2::DoReleaseMouse() { if (m_bWinCaptured) { @@ -587,77 +583,11 @@ bool wxWindowOS2::SetFont( HWND hWnd = GetHwnd(); - if (hWnd != 0) - { - char zFont[128]; - char zFacename[30]; - char zWeight[30]; - char zStyle[30]; - - // - // The fonts available for Presentation Params are just three - // outline fonts, the rest are available to the GPI, so we must - // map the families to one of these three - // - switch(rFont.GetFamily()) - { - case wxSCRIPT: - case wxDECORATIVE: - case wxROMAN: - strcpy(zFacename,"Times New Roman"); - break; - - case wxTELETYPE: - case wxMODERN: - strcpy(zFacename, "Courier"); - break; - - case wxSWISS: - case wxDEFAULT: - default: - strcpy(zFacename, "Helvetica"); - break; - } - - switch(rFont.GetWeight()) - { - default: - case wxNORMAL: - case wxLIGHT: - zWeight[0] = '\0'; - break; - - case wxBOLD: - case wxFONTWEIGHT_MAX: - strcpy(zWeight, "Bold"); - break; - } - switch(rFont.GetStyle()) - { - case wxITALIC: - case wxSLANT: - strcpy(zStyle, "Italic"); - break; - - default: - zStyle[0] = '\0'; - break; - } - sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename); - if (zWeight[0] != '\0') - { - strcat(zFont, " "); - strcat(zFont, zWeight); - } - if (zStyle[0] != '\0') - { - strcat(zFont, " "); - strcat(zFont, zStyle); - } - ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont); - } + wxOS2SetFont( hWnd + ,rFont + ); return(TRUE); -} +} // end of wxWindowOS2::SetFont bool wxWindowOS2::SetCursor( const wxCursor& rCursor @@ -1055,9 +985,20 @@ void wxWindowOS2::SubclassWin( { HWND hwnd = (HWND)hWnd; - wxASSERT_MSG( !m_fnOldWndProc, wxT("subclassing window twice?") ); wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") ); - m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc); + wxAssociateWinWithHandle( hWnd + ,(wxWindow*)this + ); + if (!wxCheckWindowWndProc( hWnd + ,(WXFARPROC)wxWndProc + )) + { + m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc); + } + else + { + m_fnOldWndProc = (WXFARPROC)NULL; + } } // end of wxWindowOS2::SubclassWin void wxWindowOS2::UnsubclassWin() @@ -1081,6 +1022,19 @@ void wxWindowOS2::UnsubclassWin() } } // end of wxWindowOS2::UnsubclassWin +bool wxCheckWindowWndProc( + WXHWND hWnd +, WXFARPROC fnWndProc +) +{ + static char zBuffer[512]; + CLASSINFO vCls; + + ::WinQueryClassName((HWND)hWnd, (LONG)512, (PCH)zBuffer); + ::WinQueryClassInfo(wxGetInstance(), (PSZ)zBuffer, &vCls); + return(fnWndProc == (WXFARPROC)vCls.pfnWindowProc); +} // end of WinGuiBase_CheckWindowWndProc + // // Make a Windows extended style from the given wxWindows window style // @@ -1305,6 +1259,27 @@ void wxWindowOS2::Clear() vDc.Clear(); } // end of wxWindowOS2::Clear +void wxWindowOS2::Update() +{ + ::WinUpdateWindow(GetHwnd()); +} // end of wxWindowOS2::Update + +void wxWindowOS2::Freeze() +{ + ::WinSendMsg(GetHwnd(), WM_VRNDISABLED, (MPARAM)0, (MPARAM)0); +} // end of wxWindowOS2::Freeze + +void wxWindowOS2::Thaw() +{ + ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0); + + // + // We need to refresh everything or otherwise he invalidated area is not + // repainted. + // + Refresh(); +} // end of wxWindowOS2::Thaw + void wxWindowOS2::Refresh( bool bEraseBack , const wxRect* pRect @@ -1392,9 +1367,17 @@ void wxWindowOS2::DoGetSize( , int* pHeight ) const { - HWND hWnd = GetHwnd(); + HWND hWnd; RECTL vRect; + if (IsKindOf(CLASSINFO(wxFrame))) + { + wxFrame* pFrame = wxDynamicCast(this, wxFrame); + hWnd = pFrame->GetFrame(); + } + else + hWnd = GetHwnd(); + ::WinQueryWindowRect(hWnd, &vRect); if (pWidth) @@ -1490,22 +1473,68 @@ void wxWindowOS2::DoGetClientSize( ) const { HWND hWnd = GetHwnd(); - HWND hWndClient; RECTL vRect; - if (IsKindOf(CLASSINFO(wxFrame))) - hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); - else - hWndClient = NULLHANDLE; - if( hWndClient == NULLHANDLE) - ::WinQueryWindowRect(GetHwnd(), &vRect); - else - ::WinQueryWindowRect(hWndClient, &vRect); + ::WinQueryWindowRect(hWnd, &vRect); + if (IsKindOf(CLASSINFO(wxDialog))) + { + RECTL vTitle; + HWND hWndTitle; + // + // For a Dialog we have to explicitly request the client portion. + // For a Frame the hWnd IS the client window + // + hWndTitle = ::WinWindowFromID(hWnd, FID_TITLEBAR); + if (::WinQueryWindowRect(hWndTitle, &vTitle)) + { + if (vTitle.yTop - vTitle.yBottom == 0) + { + // + // Dialog has not been created yet, use a default + // + vTitle.yTop = 20; + } + vRect.yTop -= (vTitle.yTop - vTitle.yBottom); + } + ULONG uStyle = ::WinQueryWindowULong(hWnd, QWL_STYLE); + + // + // Deal with borders + // + if (uStyle & FCF_DLGBORDER) + { + vRect.xLeft += 4; + vRect.xRight -= 4; + vRect.yTop -= 4; + vRect.yBottom += 4; + } + else if (uStyle & FCF_SIZEBORDER) + { + vRect.xLeft += 4; + vRect.xRight -= 4; + vRect.yTop -= 4; + vRect.yBottom += 4; + } + else if (uStyle & FCF_BORDER) + { + vRect.xLeft += 2; + vRect.xRight -= 2; + vRect.yTop -= 2; + vRect.yBottom += 2; + } + else // make some kind of adjustment or top sizers ram into the titlebar! + { + vRect.xLeft += 3; + vRect.xRight -= 3; + vRect.yTop -= 3; + vRect.yBottom += 3; + } + } if (pWidth) - *pWidth = vRect.xRight; + *pWidth = vRect.xRight - vRect.xLeft; if (pHeight) - *pHeight = vRect.yTop; + *pHeight = vRect.yTop - vRect.yBottom; } // end of wxWindowOS2::DoGetClientSize void wxWindowOS2::DoMoveWindow( @@ -1519,21 +1548,11 @@ void wxWindowOS2::DoMoveWindow( HWND hParent; wxWindow* pParent = GetParent(); - if (pParent) + if (pParent && !IsKindOf(CLASSINFO(wxDialog))) { - hParent = GetWinHwnd(pParent); - if (pParent->IsKindOf(CLASSINFO(wxFrame))) - { - if (IsKindOf(CLASSINFO(wxStatusBar)) || - IsKindOf(CLASSINFO(wxMenuBar)) || - IsKindOf(CLASSINFO(wxToolBar)) - ) - nY = pParent->GetSize().y - (nY + nHeight); - else - nY = pParent->GetClientSize().y - (nY + nHeight); - } - else - nY = pParent->GetSize().y - (nY + nHeight); + int nOS2Height = GetOS2ParentHeight(pParent); + + nY = nOS2Height - (nY + nHeight); } else { @@ -1582,8 +1601,29 @@ void wxWindowOS2::DoSetSize( GetPosition(&nCurrentX, &nCurrentY); GetSize(&nCurrentWidth, &nCurrentHeight); + // // ... and don't do anything (avoiding flicker) if it's already ok - if (nX == nCurrentX && nY == nCurrentY && + // + // + // Must convert Y coords to test for equality under OS/2 + // + int nY2 = nY; + wxWindow* pParent = (wxWindow*)GetParent(); + + if (pParent && !IsKindOf(CLASSINFO(wxDialog))) + { + int nOS2Height = GetOS2ParentHeight(pParent); + + nY2 = nOS2Height - (nY2 + nHeight); + } + else + { + RECTL vRect; + + ::WinQueryWindowRect(HWND_DESKTOP, &vRect); + nY2 = vRect.yTop - (nY2 + nHeight); + } + if (nX == nCurrentX && nY2 == nCurrentY && nWidth == nCurrentWidth && nHeight == nCurrentHeight) { return; @@ -1812,6 +1852,26 @@ void wxWindowOS2::GetTextExtent( ::WinReleasePS(hPS); } // end of wxWindow::GetTextExtent +bool wxWindowOS2::IsMouseInWindow() const +{ + // + // Get the mouse position + POINTL vPt; + + ::WinQueryPointerPos(HWND_DESKTOP, &vPt); + + // + // Find the window which currently has the cursor and go up the window + // chain until we find this window - or exhaust it + // + HWND hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPt, TRUE); + + while (hWnd && (hWnd != GetHwnd())) + hWnd = ::WinQueryWindow(hWnd, QW_PARENT); + + return hWnd != NULL; +} // end of wxWindowOS2::IsMouseInWindow + #if wxUSE_CARET && WXWIN_COMPATIBILITY // --------------------------------------------------------------------------- // Caret manipulation @@ -1887,8 +1947,8 @@ static void wxYieldForCommandsOnly() // QMSG vMsg; - while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND, - WM_COMMAND,PM_REMOVE) && vMsg.msg != WM_QUIT) + while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) + && vMsg.msg != WM_QUIT) { wxTheApp->DoMessage((WXMSG*)&vMsg); } @@ -1902,9 +1962,10 @@ bool wxWindowOS2::DoPopupMenu( , int nY ) { - HWND hWnd = GetHwnd(); - HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0; + HWND hWndOwner = GetHwnd(); + HWND hWndParent = GetHwnd(); HWND hMenu = GetHmenuOf(pMenu); + bool bIsWaiting = TRUE; pMenu->SetInvokingWindow(this); pMenu->UpdateUI(); @@ -1915,21 +1976,25 @@ bool wxWindowOS2::DoPopupMenu( wxCurrentPopupMenu = pMenu; ::WinPopupMenu( hWndParent - ,hWnd + ,hWndOwner ,hMenu ,nX ,nY ,0L - ,PU_MOUSEBUTTON2DOWN | PU_MOUSEBUTTON2 | PU_KEYBOARD + ,PU_HCONSTRAIN | PU_VCONSTRAIN | PU_MOUSEBUTTON2DOWN | PU_MOUSEBUTTON2 ); - // we need to do it righ now as otherwise the events are never going to be - // sent to wxCurrentPopupMenu from ;() - // - // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't - // help and we'd still need wxYieldForCommandsOnly() as the menu may be - // destroyed as soon as we return (it can be a local variable in the caller - // for example) and so we do need to process the event immediately - wxYieldForCommandsOnly(); + while(bIsWaiting) + { + QMSG vMsg; + + while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) + && vMsg.msg != WM_QUIT) + { + wxTheApp->DoMessage((WXMSG*)&vMsg); + } + if (vMsg.msg == WM_DESTROY || vMsg.msg == WM_QUIT) + break; + } wxCurrentPopupMenu = NULL; pMenu->SetInvokingWindow(NULL); @@ -2150,6 +2215,14 @@ bool wxWindowOS2::OS2TranslateMessage( #endif //wxUSE_ACCEL } // end of wxWindowOS2::OS2TranslateMessage +bool wxWindowOS2::OS2ShouldPreProcessMessage( + WXMSG* pMsg +) +{ + // preprocess all messages by default + return TRUE; +} // end of wxWindowOS2::OS2ShouldPreProcessMessage + // --------------------------------------------------------------------------- // message params unpackers // --------------------------------------------------------------------------- @@ -2336,6 +2409,32 @@ MRESULT wxWindowOS2::OS2WindowProc( ); break; + case WM_WINDOWPOSCHANGED: + + // + // Dialogs under OS/2 do not get WM_SIZE events at all. + // Instead they get this, which can function much like WM_SIZE + // PSWP contains the new sizes and positioning, PSWP+1 the old + // We use this because ADJUSTWINDOWPOS comes BEFORE the new + // position is added and our auto layout does a WinQueryWindowRect + // to get the CURRENT client size. That is the size used to position + // child controls, so we need to already be sized + // in order to get the child controls positoned properly. + // + if (IsKindOf(CLASSINFO(wxDialog))) + { + PSWP pSwp = (PSWP)PVOIDFROMMP(wParam); + PSWP pSwp2 = pSwp++; + + if (!(pSwp->cx == pSwp2->cx && + pSwp->cy == pSwp2->cy)) + bProcessed = HandleSize( pSwp->cx + ,pSwp->cy + ,(WXUINT)lParam + ); + } + break; + case WM_ACTIVATE: { WXWORD wState; @@ -2661,12 +2760,16 @@ MRESULT wxWindowOS2::OS2WindowProc( #endif // __WXDEBUG__ if (IsKindOf(CLASSINFO(wxFrame))) mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam); + else if (IsKindOf(CLASSINFO(wxDialog))) + mResult = ::WinDefDlgProc( m_hWnd, uMsg, wParam, lParam); else mResult = OS2DefWindowProc(uMsg, wParam, lParam); } return mResult; } // end of wxWindowOS2::OS2WindowProc +#ifndef __EMX__ +// clashes with wxDlgProc in toplevel.cpp? // // Dialog window proc // @@ -2693,6 +2796,7 @@ MRESULT wxDlgProc( return (MRESULT)0; } } // end of wxDlgProc +#endif wxWindow* wxFindWinFromHandle( WXHWND hWnd @@ -2751,183 +2855,180 @@ void wxWindowOS2::OS2DestroyWindow() { } -void wxWindowOS2::OS2DetachWindowMenu() +bool wxWindowOS2::OS2GetCreateWindowCoords( + const wxPoint& rPos +, const wxSize& rSize +, int& rnX +, int& rnY +, int& rnWidth +, int& rnHeight +) const { -#ifndef __WXUNIVERSAL__ - if (m_hMenu) - { - HMENU hMenu = (HMENU)m_hMenu; + bool bNonDefault = FALSE; - int nN = (int)::WinSendMsg(hMenu, MM_QUERYITEMCOUNT, 0, 0); - int i; - - for (i = 0; i < nN; i++) - { - wxChar zBuf[100]; - int nChars = (int)::WinSendMsg( hMenu - ,MM_QUERYITEMTEXT - ,MPFROM2SHORT(i, nN) - ,zBuf - ); - if (!nChars) - { - wxLogLastError(wxT("GetMenuString")); - continue; - } - - if (wxStrcmp(zBuf, wxT("&Window")) == 0) - { - ::WinSendMsg(hMenu, MM_DELETEITEM, MPFROM2SHORT(i, TRUE), 0); - break; - } - } + if (rPos.x == -1) + { + // + // If set x to CW_USEDEFAULT, y parameter is ignored anyhow so we can + // just as well set it to CW_USEDEFAULT as well + rnX = rnY = CW_USEDEFAULT; } -#endif // __WXUNIVERSAL__ -} // end of wxWindowOS2::OS2DetachWindowMenu + else + { + rnX = rPos.x; + rnY = rPos.y == -1 ? CW_USEDEFAULT : rPos.y; + bNonDefault = TRUE; + } + if (rSize.x == -1) + { + // + // As abobe, h is not used at all in this case anyhow + // + rnWidth = rnHeight = CW_USEDEFAULT; + } + else + { + rnWidth = rSize.x; + rnHeight = rSize.y == -1 ? CW_USEDEFAULT : rSize.y; + bNonDefault = TRUE; + } + return bNonDefault; +} // end of wxWindowOS2::OS2GetCreateWindowCoords bool wxWindowOS2::OS2Create( - WXHWND hParent -, PSZ zClass -, const wxChar* zTitle + PSZ zClass +, const char* zTitle , WXDWORD dwStyle -, long lX -, long lY -, long lWidth -, long lHeight -, WXHWND hOwner -, WXHWND WXUNUSED(hZOrder) -, unsigned long ulId +, const wxPoint& rPos +, const wxSize& rSize , void* pCtlData -, void* pPresParams , WXDWORD dwExStyle +, bool bIsChild ) { ERRORID vError; wxString sError; - long lX1 = 0L; - long lY1 = 0L; - 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 - // panel size the size of the parent window - // - lX1 = lX; - lY1 = lY; - if (lWidth > -1L) - lWidth1 = lWidth; - if (lHeight > -1L) - lHeight1 = lHeight; - - wxWndHook = this; + int nX = 0L; + int nY = 0L; + int nWidth = 0L; + int nHeight = 0L; + wxWindow* pParent = GetParent(); + HWND hWnd = NULLHANDLE; + HWND hParent; + long lControlId = 0L; + wxWindowCreationHook vHook(this); + wxString sClassName((wxChar*)zClass); + + OS2GetCreateWindowCoords( rPos + ,rSize + ,nX + ,nY + ,nWidth + ,nHeight + ); - // - // check to see if the new window is a standard control - // - if ((ULONG)zClass == (ULONG)WC_BUTTON || - (ULONG)zClass == (ULONG)WC_COMBOBOX || - (ULONG)zClass == (ULONG)WC_CONTAINER || - (ULONG)zClass == (ULONG)WC_ENTRYFIELD || - (ULONG)zClass == (ULONG)WC_FRAME || - (ULONG)zClass == (ULONG)WC_LISTBOX || - (ULONG)zClass == (ULONG)WC_MENU || - (ULONG)zClass == (ULONG)WC_NOTEBOOK || - (ULONG)zClass == (ULONG)WC_SCROLLBAR || - (ULONG)zClass == (ULONG)WC_SPINBUTTON || - (ULONG)zClass == (ULONG)WC_STATIC || - (ULONG)zClass == (ULONG)WC_TITLEBAR || - (ULONG)zClass == (ULONG)WC_VALUESET - ) - { - nControlId = ulId; - } + if (GetWindowStyleFlag() & wxPOPUP_WINDOW) + hParent = HWND_DESKTOP; else { - // no standard controls - if(wxString (wxT("wxFrameClass")) == wxString(zClass) ) + if ((bIsChild || HasFlag(wxFRAME_TOOL_WINDOW)) && pParent ) { - pszClass = WC_FRAME; - nNeedsubclass = 1; + // + // This is either a normal child window or a top level window with + // wxFRAME_TOOL_WINDOW style (see below) + // + hParent = GetHwndOf(pParent); } else { - nControlId = ulId; - if(nControlId < 0) - nControlId = FID_CLIENT; + // + // This is either a window for which no parent was specified (not + // much we can do then) or a frame without wxFRAME_TOOL_WINDOW + // style: we should use NULL parent HWND for it or it would be + // always on top of its parent which is not what we usually want + // (in fact, we only want it for frames with the special + // wxFRAME_TOOL_WINDOW as above) + // + hParent = NULL; + } + } + if (bIsChild) + { + lControlId = GetId(); + if (GetWindowStyleFlag() & wxCLIP_SIBLINGS) + { + dwStyle |= WS_CLIPSIBLINGS; } } - - HWND parent; - if ( GetWindowStyleFlag() & wxPOPUP_WINDOW ) - { - // popup windows should have desktop as parent because they shouldn't - // be limited to the parents client area as child windows usually are - parent = HWND_DESKTOP; - } - else if ( hParent ) - { - parent = hParent; - } - else - { - // top level window - parent = NULL; - } - // - // We will either have a registered class via string name or a standard PM Class via a long + // For each class "Foo" we have we also have "FooNR" ("no repaint") class + // which is the same but without CS_[HV]REDRAW class styles so using it + // ensures that the window is not fully repainted on each resize // - m_hWnd = (WXHWND)::WinCreateWindow(parent, zClass, - (PSZ)zTitle ? zTitle : wxT(""), - dwStyle, lX1, lY1, lWidth, lHeight, - hOwner, HWND_TOP, (ULONG)nControlId, - pCtlData, pPresParams); - - if (!m_hWnd) + if (GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE) { - vError = ::WinGetLastError(vHabmain); - sError = wxPMErrorToStr(vError); - wxLogError("Can't create window of class %s!. Error: %s\n", zClass, sError); - return FALSE; + sClassName += wxT("NR"); } - m_dwExStyle = dwExStyle; - ::WinSetWindowULong(m_hWnd, QWL_USER, (ULONG) this); - wxWndHook = NULL; - -#ifdef __WXDEBUG__ - wxNode* pNode = wxWinHandleList->Member(this); - if (pNode) + // + // If the window being created is a Frame's Statusbar we need to use + // the actual Frame's size, not its client + // + if (pParent) { - HWND hWnd = (HWND)pNode->GetKeyInteger(); - - if (hWnd != (HWND)m_hWnd) - + if ( pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)) || + pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) + ) { - wxLogError("A second HWND association is being added for the same window!"); + if (IsKindOf(CLASSINFO(wxStatusBar)) && + pParent->IsKindOf(CLASSINFO(wxFrame))) + { + RECTL vRect; + wxFrame* pFrame = wxDynamicCast(pParent, wxFrame); + + ::WinQueryWindowRect((HWND)pFrame->GetFrame(), &vRect); + nY = vRect.yTop - (nY + nHeight); + } + else + nY = pParent->GetSize().y - (nY + nHeight); } } -#endif - wxAssociateWinWithHandle((HWND)m_hWnd - ,this - ); - // - // Now need to subclass window. - // - if(!nNeedsubclass) + else { - wxAssociateWinWithHandle((HWND)m_hWnd,this); + RECTL vRect; + + ::WinQueryWindowRect(HWND_DESKTOP, &vRect); + nY = vRect.yTop - (nY + nHeight); } - else + m_hWnd = (WXHWND)::WinCreateWindow( (HWND)hParent + ,(PSZ)sClassName.c_str() + ,(PSZ)zTitle ? zTitle : "" + ,(ULONG)dwStyle + ,(LONG)0L + ,(LONG)0L + ,(LONG)0L + ,(LONG)0L + ,NULLHANDLE + ,HWND_TOP + ,(ULONG)lControlId + ,pCtlData + ,NULL + ); + if (!m_hWnd) { - SubclassWin(GetHWND()); + vError = ::WinGetLastError(wxGetInstance()); + sError = wxPMErrorToStr(vError); + return FALSE; } + SubclassWin(m_hWnd); + SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); + SetSize( nX + ,nY + ,nWidth + ,nHeight + ); return TRUE; -} // end of wxWindowOS2::OS2Create +} // end of WinGuiBase_Window::OS2Create // =========================================================================== // OS2 PM message handlers @@ -3000,6 +3101,13 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) { + // + // Notify the parent keeping track of focus for the kbd navigation + // purposes that we got it + // + wxChildFocusEvent vEventFocus((wxWindow *)this); + (void)GetEventHandler()->ProcessEvent(vEventFocus); + #if wxUSE_CARET // // Deal with caret @@ -3899,6 +4007,174 @@ bool wxWindowOS2::OS2OnScroll( return GetEventHandler()->ProcessEvent(vEvent); } // end of wxWindowOS2::OS2OnScroll +void wxWindowOS2::MoveChildren( + int nDiff +) +{ + SWP vSwp; + + for (wxWindowList::Node* pNode = GetChildren().GetFirst(); + pNode; + pNode = pNode->GetNext()) + { + wxWindow* pWin = pNode->GetData(); + + ::WinQueryWindowPos( GetHwndOf(pWin) + ,&vSwp + ); + if (pWin->IsKindOf(CLASSINFO(wxControl))) + { + wxControl* pCtrl; + + // + // Must deal with controls that have margins like ENTRYFIELD. The SWP + // struct of such a control will have and origin offset from its intended + // position by the width of the margins. + // + pCtrl = wxDynamicCast(pWin, wxControl); + vSwp.y -= pCtrl->GetYComp(); + vSwp.x -= pCtrl->GetXComp(); + } + ::WinSetWindowPos( GetHwndOf(pWin) + ,HWND_TOP + ,vSwp.x + ,vSwp.y - nDiff + ,vSwp.cx + ,vSwp.cy + ,SWP_MOVE + ); + if (pWin->IsKindOf(CLASSINFO(wxRadioBox))) + { + wxRadioBox* pRadioBox; + + pRadioBox = wxDynamicCast(pWin, wxRadioBox); + pRadioBox->AdjustButtons( (int)vSwp.x + ,(int)vSwp.y - nDiff + ,(int)vSwp.cx + ,(int)vSwp.cy + ,pRadioBox->GetSizeFlags() + ); + } + if (pWin->IsKindOf(CLASSINFO(wxSlider))) + { + wxSlider* pSlider; + + pSlider = wxDynamicCast(pWin, wxSlider); + pSlider->AdjustSubControls( (int)vSwp.x + ,(int)vSwp.y - nDiff + ,(int)vSwp.cx + ,(int)vSwp.cy + ,(int)pSlider->GetSizeFlags() + ); + } + } +} // end of wxWindowOS2::MoveChildren + +// +// Getting the Y position for a window, like a control, is a real +// pain. There are three sitatuions we must deal with in determining +// the OS2 to wxWindows Y coordinate. +// +// 1) The controls are created in a dialog. +// This is the easiest since a dialog is created with its original +// size so the standard: Y = ParentHeight - (Y + ControlHeight); +// +// 2) The controls are direct children of a frame +// In this instance the controls are actually children of the Frame's +// client. During creation the frame's client resizes several times +// during creation of the status bar and toolbars. The CFrame class +// will take care of this using its AlterChildPos proc. +// +// 3) The controls are children of a panel, which in turn is a child of +// a frame. +// This is the nastiest case. A panel is created as the only child of +// the frame and as such, when a frame has only one child, the child is +// expanded to fit the entire client area of the frame. Because the +// controls are created BEFORE this occurs their positions are totally +// whacked and any call to WinQueryWindowPos will return invalid +// coordinates. So for this situation we have to compare the size of +// the panel at control creation time with that of the frame client. If +// they are the same we can use the standard Y position equation. If +// not, then we must use the Frame Client's dimensions to position them +// as that will be the eventual size of the panel after the frame resizes +// it! +// +int wxWindowOS2::GetOS2ParentHeight( + wxWindowOS2* pParent +) +{ + wxWindowOS2* pGrandParent = NULL; + + // + // Case 1 + // + if (pParent->IsKindOf(CLASSINFO(wxDialog))) + return(pParent->GetClientSize().y); + + // + // Case 2 -- if we are one of the separately built standard Frame + // children, like a statusbar, menubar, or toolbar we want to + // use the frame, itself, for positioning. Otherwise we are + // child window and want to use the Frame's client. + // + else if (pParent->IsKindOf(CLASSINFO(wxFrame))) + { + if (IsKindOf(CLASSINFO(wxStatusBar)) || + IsKindOf(CLASSINFO(wxMenuBar)) || + IsKindOf(CLASSINFO(wxToolBar)) + ) + return(pParent->GetSize().y); + else + return(pParent->GetClientSize().y); + } + + // + // Case 3 -- this is for any window that is the sole child of a Frame. + // The grandparent must exist and it must be of type CFrame + // and it's height must be different. Otherwise the standard + // applies. + // + else + { + pGrandParent = pParent->GetParent(); + if (pGrandParent && + pGrandParent->IsKindOf(CLASSINFO(wxFrame)) && + pGrandParent->GetClientSize().y != pParent->GetSize().y + ) + { + int nParentHeight = 0L; + int nStatusBarHeight = 0L; + wxFrame* pFrame = wxDynamicCast(pGrandParent, wxFrame); + wxStatusBar* pStatbar = pFrame->GetStatusBar(); + + nParentHeight = pGrandParent->GetClientSize().y; + if (pStatbar) + nStatusBarHeight = pStatbar->GetSize().y; + nParentHeight -= nStatusBarHeight; + return(nParentHeight); + } + else + // + // Panel is a child of some other kind of window so we'll + // just use it's original size + // + return(pParent->GetClientSize().y); + } + return(0L); +} // end of wxWindowOS2::GetOS2ParentHeight + +wxWindowCreationHook::wxWindowCreationHook( + wxWindow* pWinBeingCreated +) +{ + gpWinBeingCreated = pWinBeingCreated; +} // end of wxWindowCreationHook::wxWindowCreationHook + +wxWindowCreationHook::~wxWindowCreationHook() +{ + gpWinBeingCreated = NULL; +} // end of wxWindowCreationHook::~wxWindowCreationHook + // =========================================================================== // global functions // ===========================================================================