From d8a3f66ca7773885b7d396b86e49457abfccd6a9 Mon Sep 17 00:00:00 2001 From: David Webster Date: Fri, 21 Dec 2001 18:08:31 +0000 Subject: [PATCH] 'Y' positioning fixes for OS/2 controls git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13147 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/os2/control.cpp | 8 +- src/os2/gauge.cpp | 4 + src/os2/radiobox.cpp | 6 +- src/os2/slider.cpp | 98 +++++++++++++++++++----- src/os2/spinbutt.cpp | 4 + src/os2/spinctrl.cpp | 14 ++-- src/os2/statline.cpp | 13 +++- src/os2/window.cpp | 172 +++++++++++++++++++++++++++++++++++++++---- 8 files changed, 272 insertions(+), 47 deletions(-) diff --git a/src/os2/control.cpp b/src/os2/control.cpp index 35551cb4b4..acf4cecf2c 100644 --- a/src/os2/control.cpp +++ b/src/os2/control.cpp @@ -141,10 +141,10 @@ bool wxControl::OS2CreateControl( ,(PSZ)zClassname // Window class ,(PSZ)rsLabel.c_str() // Initial Text ,(ULONG)dwStyle // Style flags - ,(LONG)rPos.x // X pos of origin - ,(LONG)rPos.y // Y pos of origin - ,(LONG)rSize.x // control width - ,(LONG)rSize.y // control height + ,(LONG)0 // X pos of origin + ,(LONG)0 // Y pos of origin + ,(LONG)0 // control width + ,(LONG)0 // control height ,(HWND)GetHwndOf(GetParent()) // owner window handle (same as parent ,HWND_TOP // initial z position ,(ULONG)GetId() // Window identifier diff --git a/src/os2/gauge.cpp b/src/os2/gauge.cpp index b227ebf692..c1fe612f6c 100644 --- a/src/os2/gauge.cpp +++ b/src/os2/gauge.cpp @@ -122,6 +122,7 @@ bool wxGauge::Create( int nWidth = rSize.x; int nHeight = rSize.y; long lMsStyle = 0L; + SWP vSwp; SetName(rsName); #if wxUSE_VALIDATORS @@ -173,6 +174,9 @@ bool wxGauge::Create( ); ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc); + ::WinQueryWindowPos(m_hWnd, &vSwp); + SetXComp(vSwp.x); + SetYComp(vSwp.y); SetFont(pParent->GetFont()); if (nWidth == -1L) nWidth = 50L; diff --git a/src/os2/radiobox.cpp b/src/os2/radiobox.cpp index 47a6fbdd9c..fa32d2ccad 100644 --- a/src/os2/radiobox.cpp +++ b/src/os2/radiobox.cpp @@ -86,7 +86,7 @@ void wxRadioBox::AdjustButtons( , int nY , int nWidth , int nHeight -, long lSizeFlags +, int nSizeFlags ) { wxSize vMaxSize; @@ -480,7 +480,9 @@ void wxRadioBox::DoSetSize( if (pParent) { - nYy = pParent->GetClientSize().y - (nYy + nHeight); + int nOS2Height = GetOS2ParentHeight(pParent); + + nYy = nOS2Height - (nYy + nHeight); nYOffset = nYy + nHeight; } else diff --git a/src/os2/slider.cpp b/src/os2/slider.cpp index 2a9101349e..e8558d2e8d 100644 --- a/src/os2/slider.cpp +++ b/src/os2/slider.cpp @@ -49,6 +49,80 @@ wxSlider::~wxSlider() ::WinDestroyWindow((HWND)m_hStaticValue); } // end of wxSlider::~wxSlider +void wxSlider::AdjustSubControls( + int nX +, int nY +, int nWidth +, int nHeight +, int nSizeFlags +) +{ + SWP vSwp; + int nXOffset = nX; + int nYOffset = nY; + int nCx; // slider,min,max sizes + int nCy; + int nCyf; + char zBuf[300]; + + wxGetCharSize( GetHWND() + ,&nCx + ,&nCy + ,&this->GetFont() + ); + + if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) + { + if (m_windowStyle & wxSL_LABELS ) + { + int nMinLen = 0; + int nMaxLen = 0; + + ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf); + GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont()); + + ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf); + GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont()); + + if (m_hStaticValue) + { + int nNewWidth = wxMax(nMinLen, nMaxLen); + int nValueHeight = nCyf; + + ::WinSetWindowPos( (HWND)m_hStaticValue + ,HWND_TOP + ,(LONG)nXOffset - (nNewWidth + nCx + nMinLen + nCx) + ,(LONG)nYOffset + ,(LONG)nNewWidth + ,(LONG)nValueHeight + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + } + ::WinSetWindowPos( (HWND)m_hStaticMin + ,HWND_TOP + ,(LONG)nXOffset - (nMinLen + nCx) + ,(LONG)nYOffset + ,(LONG)nMinLen + ,(LONG)nCy + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + nXOffset += nWidth + nCx; + + ::WinSetWindowPos( (HWND)m_hStaticMax + ,HWND_TOP + ,(LONG)nXOffset + ,(LONG)nYOffset + ,(LONG)nMaxLen + ,(LONG)nCy + ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW + ); + } + } + // + // Now deal with a vertical slider -- OS/2 doesn't have vertical sliders + // +} // end of wxSlider::AdjustSubControls + void wxSlider::ClearSel() { } // end of wxSlider::ClearSel @@ -345,24 +419,11 @@ void wxSlider::DoSetSize( if (pParent) { - // - // Under OS/2, where a frame window is the parent, most child windows - // that are not specific frame clients are actually children of the - // frame's client, not the frame itself, and so position themselves - // with regards to the client origin, not the frame. - // - if (pParent->IsKindOf(CLASSINFO(wxFrame))) - { - nYOffset = pParent->GetClientSize().y - (nYOffset + nOS2Height); - if (nY != -1) - nY1 = pParent->GetClientSize().y - (nY1 + nOS2Height); - } - else - { - nYOffset = pParent->GetSize().y - (nYOffset + nOS2Height); - if (nY != -1) - nY1 = pParent->GetSize().y - (nY1 + nOS2Height); - } + int nOS2ParentHeight = GetOS2ParentHeight(pParent); + + nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height); + if (nY != -1) + nY1 = nOS2ParentHeight - (nY1 + nOS2Height); } else { @@ -373,6 +434,7 @@ void wxSlider::DoSetSize( if (nY != -1) nY1 = vRect.yTop - (nY1 + nOS2Height); } + m_nSizeFlags = nSizeFlags; GetPosition( &nCurrentX ,&nCurrentY diff --git a/src/os2/spinbutt.cpp b/src/os2/spinbutt.cpp index 6e58a26322..7c9774ede3 100644 --- a/src/os2/spinbutt.cpp +++ b/src/os2/spinbutt.cpp @@ -61,6 +61,7 @@ bool wxSpinButton::Create( int nY = rPos.y; int nWidth = rSize.x; int nHeight = rSize.y; + SWP vSwp; m_min = 0; m_max = 100; @@ -128,6 +129,9 @@ bool wxSpinButton::Create( if(pParent) pParent->AddChild((wxSpinButton *)this); + ::WinQueryWindowPos(m_hWnd, &vSwp); + SetXComp(vSwp.x); + SetYComp(vSwp.y); SetFont(pParent->GetFont()); // // For OS/2 we want to hide the text portion so we can substitute an diff --git a/src/os2/spinctrl.cpp b/src/os2/spinctrl.cpp index 75a4b4589d..516ee8f9cb 100644 --- a/src/os2/spinctrl.cpp +++ b/src/os2/spinctrl.cpp @@ -129,6 +129,8 @@ bool wxSpinCtrl::Create( , const wxString& rsName ) { + SWP vSwp; + if (vId == -1) m_windowId = NewControlId(); else @@ -177,6 +179,9 @@ bool wxSpinCtrl::Create( if(pParent) pParent->AddChild((wxSpinButton *)this); SetFont(pParent->GetFont()); + ::WinQueryWindowPos(m_hWnd, &vSwp); + SetXComp(vSwp.x); + SetYComp(vSwp.y); SetSize( rPos.x ,rPos.y ,rSize.x @@ -262,12 +267,9 @@ void wxSpinCtrl::DoMoveWindow( if (pParent) { - if (pParent->IsKindOf(CLASSINFO(wxFrame))) - { - nY = pParent->GetClientSize().y - (nY + nHeight); - } - else - nY = pParent->GetSize().y - (nY + nHeight); + int nOS2Height = GetOS2ParentHeight(pParent); + + nY = nOS2Height - (nY + nHeight); } else { diff --git a/src/os2/statline.cpp b/src/os2/statline.cpp index 687c060f00..a91dfa300b 100644 --- a/src/os2/statline.cpp +++ b/src/os2/statline.cpp @@ -67,10 +67,10 @@ bool wxStaticLine::Create( ,WC_STATIC ,"" ,WS_VISIBLE | SS_TEXT | DT_VCENTER | DT_CENTER - ,rPos.x - ,rPos.y - ,vSizeReal.x - ,vSizeReal.y + ,0 + ,0 + ,0 + ,0 ,GetWinHwnd(pParent) ,HWND_TOP ,(ULONG)m_windowId @@ -83,6 +83,11 @@ bool wxStaticLine::Create( return FALSE; } SubclassWin(m_hWnd); + SetSize( rPos.x + ,rPos.y + ,rSize.x + ,rSize.y + ); return TRUE; } // end of wxStaticLine::Create diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 2c16e35794..6cf27110d2 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -1521,19 +1521,9 @@ void wxWindowOS2::DoMoveWindow( if (pParent) { - 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 { @@ -3899,6 +3889,162 @@ 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->GetSize().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 + // =========================================================================== // global functions // =========================================================================== -- 2.45.2