+ else
+ hWnd = GetHwnd();
+
+ ::WinQueryWindowRect(hWnd, &vRect);
+
+ if (pWidth)
+ *pWidth = vRect.xRight - vRect.xLeft;
+ if (pHeight )
+ // OS/2 PM is backwards from windows
+ *pHeight = vRect.yTop - vRect.yBottom;
+} // end of wxWindowOS2::DoGetSize
+
+void wxWindowOS2::DoGetPosition(
+ int* pX
+, int* pY
+) const
+{
+ HWND hWnd = GetHwnd();
+ SWP vSwp;
+ POINTL vPoint;
+ wxWindow* pParent = GetParent();
+
+ //
+ // It would seem that WinQueryWindowRect would be the correlary to
+ // the WIN32 WinGetRect, but unlike WinGetRect which returns the window
+ // origin position in screen coordinates, WinQueryWindowRect returns it
+ // relative to itself, i.e. (0,0). To get the same under PM we must
+ // us WinQueryWindowPos. This call, unlike the WIN32 call, however,
+ // returns a position relative to it's parent, so no parent adujstments
+ // are needed under OS/2. Also, windows should be created using
+ // wxWindow coordinates, i.e 0,0 is the TOP left so vSwp will already
+ // reflect that.
+ //
+ ::WinQueryWindowPos(hWnd, &vSwp);
+
+ vPoint.x = vSwp.x;
+ vPoint.y = vSwp.y;
+
+ //
+ // We may be faking the client origin. So a window that's really at (0,
+ // 30) may appear (to wxWin apps) to be at (0, 0).
+ //
+ if (pParent)
+ {
+ wxPoint vPt(pParent->GetClientAreaOrigin());
+
+ vPoint.x -= vPt.x;
+ vPoint.y -= vPt.y;
+ }
+
+ if (pX)
+ *pX = vPoint.x;
+ if (pY)
+ *pY = vPoint.y;
+} // end of wxWindowOS2::DoGetPosition
+
+void wxWindowOS2::DoScreenToClient(
+ int* pX
+, int* pY
+) const
+{
+ HWND hWnd = GetHwnd();
+ SWP vSwp;
+
+ ::WinQueryWindowPos(hWnd, &vSwp);
+
+ if (pX)
+ *pX += vSwp.x;
+ if (pY)
+ *pY += vSwp.y;
+} // end of wxWindowOS2::DoScreenToClient
+
+void wxWindowOS2::DoClientToScreen(
+ int* pX
+, int* pY
+) const
+{
+ HWND hWnd = GetHwnd();
+ SWP vSwp;
+
+ ::WinQueryWindowPos(hWnd, &vSwp);
+
+ if (pX)
+ *pX += vSwp.x;
+ if (pY)
+ *pY += vSwp.y;
+} // end of wxWindowOS2::DoClientToScreen
+
+//
+// Get size *available for subwindows* i.e. excluding menu bar etc.
+// Must be a frame type window
+//
+void wxWindowOS2::DoGetClientSize(
+ int* pWidth
+, int* pHeight
+) const
+{
+ HWND hWnd = GetHwnd();
+ RECTL 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 - vRect.xLeft;
+ if (pHeight)
+ *pHeight = vRect.yTop - vRect.yBottom;
+} // end of wxWindowOS2::DoGetClientSize
+
+void wxWindowOS2::DoMoveWindow(
+ int nX
+, int nY
+, int nWidth
+, int nHeight
+)
+{
+ RECTL vRect;
+ wxWindow* pParent = GetParent();
+
+ /* Due to OS/2's inverted coordinate system, changing the height
+ of a window requires repositioning all it's children, e.g. if
+ you want a child of height 100 to be at the top left corner of
+ the parent you need to position the lower left corner of the
+ child at (0, (height of parent - 100)), so, obviously, if the
+ height of the parent changes, the child needs to be repositioned. */
+ int nHeightDelta;
+ GetSize(0, &nHeightDelta);
+ nHeightDelta = nHeight - nHeightDelta;
+
+ if (pParent && !IsKindOf(CLASSINFO(wxDialog)))
+ {
+ int nOS2Height = GetOS2ParentHeight(pParent);
+
+ nY = nOS2Height - (nY + nHeight);
+ }
+ else
+ {
+ RECTL vRect;
+
+ ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
+ nY = vRect.yTop - (nY + nHeight);
+ }
+
+ //
+ // In the case of a frame whose client is sized, the client cannot be
+ // large than its parent frame minus its borders! This usually happens
+ // when using an autosizer to size a frame to precisely hold client
+ // controls as in the notebook sample.
+ //
+ // In this case, we may need to resize both a frame and its client so we
+ // need a quick calc of the frame border size, then if the frame
+ // (less its borders) is smaller than the client, size the frame to
+ // encompass the client with the appropriate border size.
+ //
+ if (IsKindOf(CLASSINFO(wxFrame)))
+ {
+ RECTL vFRect;
+ HWND hWndFrame;
+ int nWidthFrameDelta = 0;
+ int nHeightFrameDelta = 0;
+ int nHeightFrame = 0;
+ int nWidthFrame = 0;
+ wxFrame* pFrame;
+
+ pFrame = wxDynamicCast(this, wxFrame);
+ hWndFrame = pFrame->GetFrame();
+ ::WinQueryWindowRect(hWndFrame, &vRect);
+ ::WinMapWindowPoints(hWndFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2);
+ vFRect = vRect;
+ ::WinCalcFrameRect(hWndFrame, &vRect, TRUE);
+ nWidthFrameDelta = ((vRect.xLeft - vFRect.xLeft) + (vFRect.xRight - vRect.xRight));
+ nHeightFrameDelta = ((vRect.yBottom - vFRect.yBottom) + (vFRect.yTop - vRect.yTop));
+ nWidthFrame = vFRect.xRight - vFRect.xLeft;
+ nHeightFrame = vFRect.yTop - vFRect.yBottom;
+
+ if (nWidth == vFRect.xRight - vFRect.xLeft &&
+ nHeight == vFRect.yTop - vFRect.yBottom)
+ {
+ //
+ // In this case the caller is not aware of OS/2's need to size both
+ // the frame and it's client and is really only moving the window,
+ // not resizeing it. So move the frame, and back off the sizes
+ // for a proper client fit.
+ //
+ ::WinSetWindowPos( hWndFrame
+ ,HWND_TOP
+ ,(LONG)nX - (vRect.xLeft - vFRect.xLeft)
+ ,(LONG)nY - (vRect.yBottom - vFRect.yBottom)
+ ,(LONG)0
+ ,(LONG)0
+ ,SWP_MOVE
+ );
+ nX += (vRect.xLeft - vFRect.xLeft);
+ nY += (vRect.yBottom - vFRect.yBottom);
+ nWidth -= nWidthFrameDelta;
+ nHeight -= nHeightFrameDelta;
+ }
+ else
+ {
+ if (nWidth > nWidthFrame - nHeightFrameDelta ||
+ nHeight > nHeightFrame - nHeightFrameDelta)
+ {
+ ::WinSetWindowPos( hWndFrame
+ ,HWND_TOP
+ ,(LONG)nX - (vRect.xLeft - vFRect.xLeft)
+ ,(LONG)nY - (vRect.yBottom - vFRect.yBottom)
+ ,(LONG)nWidth + nWidthFrameDelta
+ ,(LONG)nHeight + nHeightFrameDelta
+ ,SWP_MOVE | SWP_SIZE
+ );
+ }
+ }
+ }
+
+ ::WinSetWindowPos( GetHwnd()
+ ,HWND_TOP
+ ,(LONG)nX
+ ,(LONG)nY
+ ,(LONG)nWidth
+ ,(LONG)nHeight
+ ,SWP_SIZE | SWP_MOVE
+ );
+ if (m_vWinSwp.cx == 0 && m_vWinSwp.cy == 0 && m_vWinSwp.fl == 0)
+ //
+ // Uninitialized
+ //
+ ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp);
+ else
+ {
+ int nYDiff = m_vWinSwp.cy - nHeight;
+
+ //
+ // Handle resizing of scrolled windows. The target or window to
+ // be scrolled is the owner (gets the scroll notificaitons). The
+ // parent is usually the parent frame of the scrolled panel window.
+ // In order to show the scrollbars the target window will be shrunk
+ // by the size of the scroll bar widths (20) and moved in the X and Y
+ // directon. That value will be computed as part of the diff for
+ // moving the children. Everytime the window is sized the
+ // toplevel OnSize is going to resize the panel to fit the client
+ // or the whole sizer and will need to me resized. This will send
+ // a WM_SIZE out which will be intercepted by the ScrollHelper
+ // which will cause the scrollbars to be displayed via the SetScrollbar
+ // call in CWindow.
+ //
+ if ( IsKindOf(CLASSINFO(wxGenericScrolledWindow)) ||
+ IsKindOf(CLASSINFO(wxScrolledWindow))
+ )
+ {
+ int nAdjustWidth = 0;
+ int nAdjustHeight = 0;
+ SWP vSwpScroll;
+
+ if (GetScrollBarHorz() == NULLHANDLE ||
+ !WinIsWindowShowing(GetScrollBarHorz()))
+ nAdjustHeight = 0L;
+ else
+ nAdjustHeight = 20L;
+ if (GetScrollBarVert() == NULLHANDLE ||
+ !WinIsWindowShowing(GetScrollBarVert()))
+ nAdjustWidth = 0L;
+ else
+ nAdjustWidth = 20L;
+ ::WinQueryWindowPos(GetHWND(), &vSwpScroll);
+ ::WinSetWindowPos( GetHWND()
+ ,HWND_TOP
+ ,vSwpScroll.x
+ ,vSwpScroll.y + nAdjustHeight
+ ,vSwpScroll.cx - nAdjustWidth
+ ,vSwpScroll.cy - nAdjustHeight
+ ,SWP_MOVE | SWP_SIZE
+ );
+ nYDiff += nAdjustHeight;
+ }
+ MoveChildren(nYDiff);
+ ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp);
+ }
+ MoveChildren(nHeightDelta);
+} // end of wxWindowOS2::DoMoveWindow
+
+//
+// Set the size of the window: if the dimensions are positive, just use them,
+// but if any of them is equal to -1, it means that we must find the value for
+// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
+// which case -1 is a valid value for x and y)
+//
+// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
+// the width/height to best suit our contents, otherwise we reuse the current
+// width/height
+//
+void wxWindowOS2::DoSetSize(
+ int nX
+, int nY
+, int nWidth
+, int nHeight
+, int nSizeFlags
+)
+{
+ //
+ // Get the current size and position...
+ //
+ int nCurrentX;
+ int nCurrentY;
+ int nCurrentWidth;
+ int nCurrentHeight;
+ wxSize vSize(-1, -1);
+
+ GetPosition(&nCurrentX, &nCurrentY);
+ GetSize(&nCurrentWidth, &nCurrentHeight);
+
+ //
+ // ... and don't do anything (avoiding flicker) if it's already ok
+ //
+ //
+ // Must convert Y coords to test for equality under OS/2
+ //
+ int nY2 = nY;
+
+ if (nX == nCurrentX && nY2 == nCurrentY &&
+ nWidth == nCurrentWidth && nHeight == nCurrentHeight)
+ {
+ return;
+ }
+
+ if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+ nX = nCurrentX;
+ if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+ nY = nCurrentY;
+
+ AdjustForParentClientOrigin(nX, nY, nSizeFlags);
+
+ if (nWidth == -1)
+ {
+ if (nSizeFlags & wxSIZE_AUTO_WIDTH)
+ {
+ vSize = DoGetBestSize();
+ nWidth = vSize.x;
+ }
+ else
+ {
+ //
+ // Just take the current one
+ //
+ nWidth = nCurrentWidth;
+ }
+ }
+
+ if (nHeight == -1)
+ {
+ if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
+ {
+ if (vSize.x == -1)
+ {
+ vSize = DoGetBestSize();
+ }
+ nHeight = vSize.y;
+ }
+ else
+ {
+ // just take the current one
+ nHeight = nCurrentHeight;
+ }
+ }
+
+ DoMoveWindow( nX
+ ,nY
+ ,nWidth
+ ,nHeight
+ );
+} // end of wxWindowOS2::DoSetSize
+
+void wxWindowOS2::DoSetClientSize(
+ int nWidth
+, int nHeight
+)
+{
+ POINTL vPoint;
+ int nActualWidth;
+ int nActualHeight;
+ wxWindow* pParent = (wxWindow*)GetParent();
+ HWND hParentWnd = (HWND)0;
+
+ if (pParent)
+ hParentWnd = (HWND)pParent->GetHWND();
+
+ if (IsKindOf(CLASSINFO(wxFrame)))
+ {
+ wxFrame* pFrame = wxDynamicCast(this, wxFrame);
+ HWND hFrame = pFrame->GetFrame();
+ RECTL vRect;
+ RECTL vRect2;
+ RECTL vRect3;
+
+ ::WinQueryWindowRect(GetHwnd(), &vRect2);
+ ::WinQueryWindowRect(hFrame, &vRect);
+ ::WinQueryWindowRect(hParentWnd, &vRect3);
+ nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
+ nActualHeight = vRect2.yTop - vRect2.yBottom - vRect.yTop + nHeight;
+
+ vPoint.x = vRect2.xLeft;
+ vPoint.y = vRect2.yBottom;
+ if (pParent)
+ {
+ vPoint.x -= vRect3.xLeft;
+ vPoint.y -= vRect3.yBottom;
+ }
+ }
+ else
+ {
+ int nX;
+ int nY;
+
+ GetPosition(&nX, &nY);
+ nActualWidth = nWidth;
+ nActualHeight = nHeight;
+
+ vPoint.x = nX;
+ vPoint.y = nY;
+ }
+ DoMoveWindow( vPoint.x
+ ,vPoint.y
+ ,nActualWidth
+ ,nActualHeight
+ );
+
+ wxSizeEvent vEvent( wxSize( nWidth
+ ,nHeight
+ )
+ ,m_windowId
+ );
+
+ vEvent.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindowOS2::DoSetClientSize
+
+// ---------------------------------------------------------------------------
+// text metrics
+// ---------------------------------------------------------------------------
+
+int wxWindowOS2::GetCharHeight() const
+{
+ HPS hPs;
+ FONTMETRICS vFontMetrics;
+
+ hPs = ::WinGetPS(GetHwnd());
+
+ if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
+ {
+ ::WinReleasePS(hPs);
+ return (0);
+ }
+ ::WinReleasePS(hPs);
+ return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender);
+} // end of wxWindowOS2::GetCharHeight
+
+int wxWindowOS2::GetCharWidth() const
+{
+ HPS hPs;
+ FONTMETRICS vFontMetrics;
+
+ hPs = ::WinGetPS(GetHwnd());
+
+ if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
+ {
+ ::WinReleasePS(hPs);
+ return (0);
+ }
+ ::WinReleasePS(hPs);
+ return(vFontMetrics.lAveCharWidth);
+} // end of wxWindowOS2::GetCharWidth
+
+void wxWindowOS2::GetTextExtent(
+ const wxString& rString
+, int* pX
+, int* pY
+, int* pDescent
+, int* pExternalLeading
+, const wxFont* pTheFont
+) const
+{
+ POINTL avPoint[TXTBOX_COUNT];
+ POINTL vPtMin;
+ POINTL vPtMax;
+ int i;
+ int l;
+ FONTMETRICS vFM; // metrics structure
+ BOOL bRc = FALSE;
+ char* pStr;
+ HPS hPS;
+
+
+ hPS = ::WinGetPS(GetHwnd());
+
+ l = rString.Length();
+ if (l > 0L)
+ {
+ pStr = (PCH)rString.c_str();
+
+ //
+ // In world coordinates.
+ //
+ bRc = ::GpiQueryTextBox( hPS
+ ,l
+ ,pStr
+ ,TXTBOX_COUNT // return maximum information
+ ,avPoint // array of coordinates points
+ );
+ if (bRc)
+ {
+ vPtMin.x = avPoint[0].x;
+ vPtMax.x = avPoint[0].x;
+ vPtMin.y = avPoint[0].y;
+ vPtMax.y = avPoint[0].y;
+ for (i = 1; i < 4; i++)
+ {
+ if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
+ if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
+ if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
+ if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
+ }
+ bRc = ::GpiQueryFontMetrics( hPS
+ ,sizeof(FONTMETRICS)
+ ,&vFM
+ );
+ if (!bRc)
+ {
+ vPtMin.x = 0;
+ vPtMin.y = 0;
+ vPtMax.x = 0;
+ vPtMax.y = 0;
+ }
+ }
+ else
+ {
+ vPtMin.x = 0;
+ vPtMin.y = 0;
+ vPtMax.x = 0;
+ vPtMax.y = 0;
+ }
+ }
+ else
+ {
+ vPtMin.x = 0;
+ vPtMin.y = 0;
+ vPtMax.x = 0;
+ vPtMax.y = 0;
+ }
+ if (pX)
+ *pX = (vPtMax.x - vPtMin.x + 1);
+ if (pY)
+ *pY = (vPtMax.y - vPtMin.y + 1);
+ if (pDescent)
+ {
+ if (bRc)
+ *pDescent = vFM.lMaxDescender;
+ else
+ *pDescent = 0;
+ }
+ if (pExternalLeading)
+ {
+ if (bRc)
+ *pExternalLeading = vFM.lExternalLeading;
+ else
+ *pExternalLeading = 0;
+ }
+ ::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
+
+
+// ---------------------------------------------------------------------------
+// popup menu
+// ---------------------------------------------------------------------------
+//
+#if wxUSE_MENUS_NATIVE
+bool wxWindowOS2::DoPopupMenu(
+ wxMenu* pMenu
+, int nX
+, int nY
+)
+{
+ HWND hWndOwner = GetHwnd();
+ HWND hWndParent = GetHwnd();
+ HWND hMenu = GetHmenuOf(pMenu);
+ bool bIsWaiting = TRUE;
+ int nHeight;
+
+ // Protect against recursion
+ if (wxCurrentPopupMenu)
+ return false;
+
+ pMenu->SetInvokingWindow(this);
+ pMenu->UpdateUI();
+
+ if ( nX == -1 && nY == -1 )
+ {
+ wxPoint mouse = wxGetMousePosition();
+ nX = mouse.x; nY = mouse.y;
+ }
+ else
+ {
+ DoClientToScreen( &nX
+ ,&nY
+ );
+ DoGetSize(0,&nHeight);
+ nY = nHeight - nY;
+ }
+ wxCurrentPopupMenu = pMenu;
+
+ ::WinPopupMenu( hWndParent
+ ,hWndOwner
+ ,hMenu
+ ,nX
+ ,nY
+ ,0L
+ ,PU_HCONSTRAIN | PU_VCONSTRAIN | PU_MOUSEBUTTON1 | PU_KEYBOARD
+ );
+
+ while(bIsWaiting)
+ {
+ QMSG vMsg;
+
+ ::WinGetMsg(vHabmain,&vMsg, (HWND)0, 0, 0);
+ if (vMsg.msg == WM_COMMAND)
+ bIsWaiting = FALSE;
+ ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
+ }
+
+ wxCurrentPopupMenu = NULL;
+ pMenu->SetInvokingWindow(NULL);
+ return TRUE;
+} // end of wxWindowOS2::DoPopupMenu
+#endif // wxUSE_MENUS_NATIVE
+
+// ===========================================================================
+// pre/post message processing
+// ===========================================================================
+
+MRESULT wxWindowOS2::OS2DefWindowProc(
+ WXUINT uMsg
+, WXWPARAM wParam
+, WXLPARAM lParam
+)
+{
+ if (m_fnOldWndProc)
+ return (MRESULT)m_fnOldWndProc(GetHWND(), uMsg, (MPARAM)wParam, (MPARAM)lParam);
+ else
+ return ::WinDefWindowProc(GetHWND(), uMsg, (MPARAM)wParam, (MPARAM)lParam);
+} // end of wxWindowOS2::OS2DefWindowProc
+
+bool wxWindowOS2::OS2ProcessMessage(
+ WXMSG* pMsg
+)
+{
+// wxUniversal implements tab traversal itself
+#ifndef __WXUNIVERSAL__
+ QMSG* pQMsg = (QMSG*)pMsg;
+
+ if (m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL))
+ {
+ //
+ // Intercept dialog navigation keys
+ //
+ bool bProcess = TRUE;
+ USHORT uKeyFlags = SHORT1FROMMP(pQMsg->mp1);
+
+ if (uKeyFlags & KC_KEYUP)
+ bProcess = FALSE;
+
+ if (uKeyFlags & KC_ALT)
+ bProcess = FALSE;
+
+ if (!(uKeyFlags & KC_VIRTUALKEY))
+ bProcess = FALSE;
+
+ if (bProcess)
+ {
+ bool bCtrlDown = IsCtrlDown();
+ bool bShiftDown = IsShiftDown();
+
+ //
+ // WM_QUERYDLGCODE: ask the control if it wants the key for itself,
+ // don't process it if it's the case (except for Ctrl-Tab/Enter
+ // combinations which are always processed)
+ //
+ ULONG ulDlgCode = 0;
+
+ if (!bCtrlDown)
+ {
+ ulDlgCode = (ULONG)::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0);
+ }
+
+ bool bForward = TRUE;
+ bool bWindowChange = FALSE;
+
+ switch (SHORT2FROMMP(pQMsg->mp2))
+ {
+ //
+ // Going to make certain assumptions about specific types of controls
+ // here, so we may have to alter some things later if they prove invalid
+ //
+ case VK_TAB:
+ //
+ // Shift tabl will always be a nav-key but tabs may be wanted
+ //
+ if (!bShiftDown)
+ {
+ bProcess = FALSE;
+ }
+ else
+ {
+ //
+ // Entry Fields want tabs for themselve usually
+ //
+ switch (ulDlgCode)
+ {
+ case DLGC_ENTRYFIELD:
+ case DLGC_MLE:
+ bProcess = TRUE;
+ break;
+
+ default:
+ bProcess = FALSE;
+ }
+
+ //
+ // Ctrl-Tab cycles thru notebook pages
+ //
+ bWindowChange = bCtrlDown;
+ bForward = !bShiftDown;
+ }
+ break;
+
+ case VK_UP:
+ case VK_LEFT:
+ if (bCtrlDown)
+ bProcess = FALSE;
+ else
+ bForward = FALSE;
+ break;
+
+ case VK_DOWN:
+ case VK_RIGHT:
+ if (bCtrlDown)
+ bProcess = FALSE;
+ break;
+
+ case VK_ENTER:
+ {
+ if (bCtrlDown)
+ {
+ //
+ // ctrl-enter is not processed
+ //
+ return FALSE;
+ }
+ else if (ulDlgCode & DLGC_BUTTON)
+ {
+ //
+ // buttons want process Enter themselevs
+ //
+ bProcess = FALSE;
+ }
+ else
+ {
+ wxButton* pBtn = wxDynamicCast( GetDefaultItem()
+ ,wxButton
+ );
+
+ if (pBtn && pBtn->IsEnabled())
+ {
+ //
+ // If we do have a default button, do press it
+ //
+ pBtn->OS2Command(BN_CLICKED, 0 /* unused */);
+ return TRUE;
+ }
+ else if (!IsTopLevel())
+ {
+ //
+ // if not a top level window, let parent
+ // handle it
+ //
+ return FALSE;
+ }
+ // else: but if it does not it makes sense to make
+ // it work like a TAB - and that's what we do.
+ // Note that Ctrl-Enter always works this way.
+ }
+ }
+ break;
+
+ default:
+ bProcess = FALSE;
+ }
+
+ if (bProcess)
+ {
+ wxNavigationKeyEvent vEvent;
+
+ vEvent.SetDirection(bForward);
+ vEvent.SetWindowChange(bWindowChange);
+ vEvent.SetEventObject(this);
+
+ if (GetEventHandler()->ProcessEvent(vEvent))
+ {
+ wxButton* pBtn = wxDynamicCast(FindFocus(), wxButton);
+
+ if (pBtn)
+ {
+ //
+ // The button which has focus should be default
+ //
+ pBtn->SetDefault();
+ }
+ return TRUE;
+ }
+ }
+ }
+ //
+ // Let Dialogs process
+ //
+ if (::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0));
+ return TRUE;
+ }
+#else
+ pMsg = pMsg; // just shut up the compiler
+#endif // __WXUNIVERSAL__
+
+ return FALSE;
+} // end of wxWindowOS2::OS2ProcessMessage
+
+bool wxWindowOS2::OS2TranslateMessage(
+ WXMSG* pMsg
+)
+{
+#if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
+ return m_acceleratorTable.Translate(m_hWnd, pMsg);
+#else
+ pMsg = pMsg;
+ return FALSE;
+#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
+// ---------------------------------------------------------------------------
+
+void wxWindowOS2::UnpackCommand(
+ WXWPARAM wParam
+, WXLPARAM lParam
+, WORD* pId
+, WXHWND* phWnd
+, WORD* pCmd
+)
+{
+ *pId = LOWORD(wParam);
+ *phWnd = NULL; // or may be GetHWND() ?
+ *pCmd = LOWORD(lParam);
+} // end of wxWindowOS2::UnpackCommand
+
+void wxWindowOS2::UnpackActivate(
+ WXWPARAM wParam
+, WXLPARAM lParam
+, WXWORD* pState
+, WXHWND* phWnd
+)
+{
+ *pState = LOWORD(wParam);
+ *phWnd = (WXHWND)lParam;
+} // end of wxWindowOS2::UnpackActivate
+
+void wxWindowOS2::UnpackScroll(
+ WXWPARAM wParam
+, WXLPARAM lParam
+, WXWORD* pCode
+, WXWORD* pPos
+, WXHWND* phWnd
+)
+{
+ ULONG ulId;
+ HWND hWnd;
+
+ ulId = (ULONG)LONGFROMMP(wParam);
+ hWnd = ::WinWindowFromID(GetHwnd(), ulId);
+ if (hWnd == m_hWndScrollBarHorz || hWnd == m_hWndScrollBarVert)
+ *phWnd = NULLHANDLE;
+ else
+ *phWnd = hWnd;
+
+ *pPos = SHORT1FROMMP(lParam);
+ *pCode = SHORT2FROMMP(lParam);
+} // end of wxWindowOS2::UnpackScroll
+
+void wxWindowOS2::UnpackMenuSelect(
+ WXWPARAM wParam
+, WXLPARAM lParam
+, WXWORD* pItem
+, WXWORD* pFlags
+, WXHMENU* phMenu
+)
+{
+ *pItem = (WXWORD)LOWORD(wParam);
+ *pFlags = HIWORD(wParam);
+ *phMenu = (WXHMENU)lParam;
+} // end of wxWindowOS2::UnpackMenuSelect
+
+// ---------------------------------------------------------------------------
+// Main wxWidgets window proc and the window proc for wxWindow
+// ---------------------------------------------------------------------------
+
+//
+// Hook for new window just as it's being created, when the window isn't yet
+// associated with the handle
+//
+wxWindowOS2* wxWndHook = NULL;
+
+//
+// Main window proc
+//
+MRESULT EXPENTRY wxWndProc(
+ HWND hWnd
+, ULONG ulMsg
+, MPARAM wParam
+, MPARAM lParam
+)
+{
+ wxWindowOS2* pWnd = wxFindWinFromHandle((WXHWND)hWnd);
+
+ //
+ // 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;
+
+
+ //
+ // Stop right here if we don't have a valid handle in our wxWindow object.
+ //
+ if (pWnd && !pWnd->GetHWND())
+ {
+ pWnd->SetHWND((WXHWND) hWnd);
+ rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam );
+ pWnd->SetHWND(0);
+ }
+ else
+ {
+ if (pWnd)
+ {
+ rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam);
+ if ( (pWnd->GetScrollBarHorz() != NULLHANDLE ||
+ pWnd->GetScrollBarVert() != NULLHANDLE) &&
+ ulMsg == WM_PAINT)
+ {
+ if (pWnd->GetScrollBarHorz() != NULLHANDLE)
+ ::WinInvalidateRect(pWnd->GetScrollBarHorz(), NULL, TRUE);
+ if (pWnd->GetScrollBarVert() != NULLHANDLE)
+ ::WinInvalidateRect(pWnd->GetScrollBarVert(), NULL, TRUE);
+ }
+ }
+ else
+ rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
+ }
+
+ return rc;
+} // end of wxWndProc
+
+//
+// We will add (or delete) messages we need to handle at this default
+// level as we go
+//
+MRESULT wxWindowOS2::OS2WindowProc(
+ WXUINT uMsg
+, WXWPARAM wParam
+, WXLPARAM lParam
+)
+{
+ //
+ // Did we process the uMsg?
+ //
+ bool bProcessed = FALSE;
+ MRESULT mResult;
+
+ //
+ // For most messages we should return 0 when we do process the message
+ //
+ mResult = (MRESULT)0;
+
+ switch (uMsg)
+ {
+ case WM_CREATE:
+ {
+ bool bMayCreate;
+
+ bProcessed = HandleCreate( (WXLPCREATESTRUCT)lParam
+ ,&bMayCreate
+ );
+ if (bProcessed)
+ {
+ //
+ // Return 0 to bAllow window creation
+ //
+ mResult = (MRESULT)(bMayCreate ? 0 : -1);
+ }
+ }
+ break;
+
+ case WM_DESTROY:
+ HandleDestroy();
+ bProcessed = TRUE;
+ break;
+
+ case WM_MOVE:
+ bProcessed = HandleMove( LOWORD(lParam)
+ ,HIWORD(lParam)
+ );
+ break;
+
+ case WM_SIZE:
+ bProcessed = HandleSize( LOWORD(lParam)
+ ,HIWORD(lParam)
+ ,(WXUINT)wParam
+ );
+ 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)) || IsKindOf(CLASSINFO(wxFrame)))
+ {
+ 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
+ );
+ if (IsKindOf(CLASSINFO(wxFrame)))
+ {
+ wxFrame* pFrame = wxDynamicCast(this, wxFrame);
+
+ if (pFrame)
+ {
+ if (pFrame->GetStatusBar())
+ pFrame->PositionStatusBar();
+ if (pFrame->GetToolBar())
+ pFrame->PositionToolBar();
+ }
+ }
+ }
+ break;
+
+ case WM_ACTIVATE:
+ {
+ WXWORD wState;
+ WXHWND hWnd;
+
+ UnpackActivate( wParam
+ ,lParam
+ ,&wState
+ ,&hWnd
+ );
+
+ bProcessed = HandleActivate( wState
+ ,(WXHWND)hWnd
+ );
+ bProcessed = FALSE;
+ }
+ break;
+
+ case WM_SETFOCUS:
+ if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
+ bProcessed = HandleSetFocus((WXHWND)(HWND)wParam);
+ else
+ bProcessed = HandleKillFocus((WXHWND)(HWND)wParam);
+ break;
+
+ case WM_PAINT:
+ bProcessed = HandlePaint();
+ break;
+
+ case WM_CLOSE:
+ //
+ // Don't let the DefWindowProc() destroy our window - we'll do it
+ // ourselves in ~wxWindow
+ //
+ bProcessed = TRUE;
+ mResult = (MRESULT)TRUE;
+ break;
+
+ case WM_SHOW:
+ bProcessed = HandleShow(wParam != 0, (int)lParam);
+ break;
+
+ //
+ // Under OS2 PM Joysticks are treated just like mouse events
+ // The "Motion" events will be prevelent in joysticks
+ //
+ case WM_MOUSEMOVE:
+ case WM_BUTTON1DOWN:
+ case WM_BUTTON1UP:
+ case WM_BUTTON1DBLCLK:
+ case WM_BUTTON1MOTIONEND:
+ case WM_BUTTON1MOTIONSTART:
+ case WM_BUTTON2DOWN:
+ case WM_BUTTON2UP:
+ case WM_BUTTON2DBLCLK:
+ case WM_BUTTON2MOTIONEND:
+ case WM_BUTTON2MOTIONSTART:
+ case WM_BUTTON3DOWN:
+ case WM_BUTTON3UP:
+ case WM_BUTTON3DBLCLK:
+ case WM_BUTTON3MOTIONEND:
+ case WM_BUTTON3MOTIONSTART:
+ {
+ if (uMsg == WM_BUTTON1DOWN && AcceptsFocus())
+ SetFocus();
+
+ short nX = LOWORD(wParam);
+ short nY = HIWORD(wParam);
+
+ //
+ // Redirect the event to a static control if necessary
+ //
+ if (this == GetCapture())
+ {
+ bProcessed = HandleMouseEvent( uMsg
+ ,nX
+ ,nY
+ ,(WXUINT)SHORT2FROMMP(lParam)
+ );
+ }
+ else
+ {
+ wxWindow* pWin = FindWindowForMouseEvent( this
+ ,&nX
+ ,&nY
+ );
+ if (!pWin->IsOfStandardClass())
+ {
+ if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() )
+ pWin->SetFocus();
+ }
+ bProcessed = pWin->HandleMouseEvent( uMsg
+ ,nX
+ ,nY
+ ,(WXUINT)SHORT2FROMMP(lParam)
+ );
+ }
+ }
+ break;
+
+ case WM_SYSCOMMAND:
+ bProcessed = HandleSysCommand(wParam, lParam);
+ break;
+
+ case WM_COMMAND:
+ {
+ WORD id, cmd;
+ WXHWND hwnd;
+ UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
+
+ bProcessed = HandleCommand(id, cmd, hwnd);
+ }
+ break;
+
+ //
+ // For these messages we must return TRUE if process the message
+ //
+ case WM_DRAWITEM:
+ case WM_MEASUREITEM:
+ {
+ int nIdCtrl = (UINT)wParam;
+
+ if ( uMsg == WM_DRAWITEM )
+ {
+ bProcessed = OS2OnDrawItem(nIdCtrl,
+ (WXDRAWITEMSTRUCT *)lParam);
+ }
+ else
+ {
+ return MRFROMLONG(OS2OnMeasureItem( nIdCtrl
+ ,(WXMEASUREITEMSTRUCT *)lParam
+ ));
+ }
+
+ if ( bProcessed )
+ mResult = (MRESULT)TRUE;
+ }
+ break;
+
+ case WM_QUERYDLGCODE:
+ if (!IsOfStandardClass())
+ {
+ if ( m_lDlgCode )
+ {
+ mResult = (MRESULT)m_lDlgCode;
+ bProcessed = TRUE;
+ }
+ }
+ //
+ //else: get the dlg code from the DefWindowProc()
+ //
+ break;
+
+ //
+ // In OS/2 PM all keyboard events are of the WM_CHAR type. Virtual key and key-up
+ // and key-down events are obtained from the WM_CHAR params.
+ //
+ case WM_CHAR:
+ {
+ USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
+
+ if (uKeyFlags & KC_KEYUP)
+ {
+ //TODO: check if the cast to WXWORD isn't causing trouble
+ bProcessed = HandleKeyUp(wParam, lParam);
+ break;
+ }
+ else // keydown event
+ {
+ m_bLastKeydownProcessed = FALSE;
+ //
+ // If this has been processed by an event handler,
+ // return 0 now (we've handled it). DON't RETURN
+ // we still need to process further
+ //
+ m_bLastKeydownProcessed = HandleKeyDown(wParam, lParam);
+ if (uKeyFlags & KC_VIRTUALKEY)
+ {
+ USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
+
+ //
+ // We consider these message "not interesting" to OnChar
+ //
+ switch(uVk)
+ {
+ case VK_SHIFT:
+ case VK_CTRL:
+ case VK_MENU:
+ case VK_CAPSLOCK:
+ case VK_NUMLOCK:
+ case VK_SCRLLOCK:
+ bProcessed = TRUE;
+ break;
+
+ // Avoid duplicate messages to OnChar for these ASCII keys: they
+ // will be translated by TranslateMessage() and received in WM_CHAR
+ case VK_ESC:
+ case VK_ENTER:
+ case VK_BACKSPACE:
+ case VK_TAB:
+ // But set processed to FALSE, not TRUE to still pass them to
+ // the control's default window proc - otherwise built-in
+ // keyboard handling won't work
+ bProcessed = FALSE;
+ break;
+
+ default:
+ bProcessed = HandleChar(wParam, lParam);
+ }
+ break;
+ }
+ else // WM_CHAR -- Always an ASCII character
+ {
+ if (m_bLastKeydownProcessed)
+ {
+ //
+ // The key was handled in the EVT_KEY_DOWN and handling
+ // a key in an EVT_KEY_DOWN handler is meant, by
+ // design, to prevent EVT_CHARs from happening
+ //
+ m_bLastKeydownProcessed = FALSE;
+ bProcessed = TRUE;
+ }
+ else // do generate a CHAR event
+ {
+ bProcessed = HandleChar(wParam, lParam, TRUE);
+ break;
+ }
+ }
+ }
+ }
+
+ case WM_HSCROLL:
+ case WM_VSCROLL:
+ {
+ WXWORD wCode;
+ WXWORD wPos;
+ WXHWND hWnd;
+ UnpackScroll( wParam
+ ,lParam
+ ,&wCode
+ ,&wPos
+ ,&hWnd
+ );
+
+ bProcessed = OS2OnScroll( uMsg == WM_HSCROLL ? wxHORIZONTAL
+ : wxVERTICAL
+ ,wCode
+ ,wPos
+ ,hWnd
+ );
+ }
+ break;
+
+ case WM_CONTROL:
+ switch(SHORT2FROMMP(wParam))
+ {
+ case BN_PAINT:
+ {
+ HWND hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
+ wxWindowOS2* pWin = wxFindWinFromHandle(hWnd);
+
+ if (!pWin)
+ {
+ bProcessed = FALSE;
+ break;
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxBitmapButton)))
+ {
+ wxBitmapButton* pBitmapButton = wxDynamicCast(pWin, wxBitmapButton);
+
+ pBitmapButton->OS2OnDraw((WXDRAWITEMSTRUCT *)lParam);
+ }
+ return 0;
+ }
+ break;
+
+ case BKN_PAGESELECTEDPENDING:
+ {
+ PPAGESELECTNOTIFY pPage = (PPAGESELECTNOTIFY)lParam;
+
+ if ((pPage->ulPageIdNew != pPage->ulPageIdCur) &&
+ (pPage->ulPageIdNew > 0L && pPage->ulPageIdCur > 0L))
+ {
+ wxWindowOS2* pWin = wxFindWinFromHandle(pPage->hwndBook);
+ wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
+ ,(int)SHORT1FROMMP(wParam)
+ ,(int)pPage->ulPageIdNew
+ ,(int)pPage->ulPageIdCur
+ );
+ if (!pWin)
+ {
+ bProcessed = FALSE;
+ break;
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxNotebook)))
+ {
+ wxNotebook* pNotebook = wxDynamicCast(pWin, wxNotebook);
+
+ vEvent.SetEventObject(pWin);
+ pNotebook->OnSelChange(vEvent);
+ bProcessed = TRUE;
+ }
+ else
+ bProcessed = FALSE;
+ }
+ else
+ bProcessed = FALSE;
+ }
+ break;
+
+ case BN_CLICKED: // Dups as LN_SELECT and CBN_LBSELECT
+ {
+ HWND hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
+ wxWindowOS2* pWin = wxFindWinFromHandle(hWnd);
+
+ if (!pWin)
+ {
+ bProcessed = FALSE;
+ break;
+ }
+ //
+ // Simulate a WM_COMMAND here, as wxWidgets expects all control
+ // button clicks to generate WM_COMMAND msgs, not WM_CONTROL
+ //
+ if (pWin->IsKindOf(CLASSINFO(wxRadioBox)))
+ {
+ wxRadioBox* pRadioBox = wxDynamicCast(pWin, wxRadioBox);
+
+ pRadioBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxRadioButton)))
+ {
+ wxRadioButton* pRadioButton = wxDynamicCast(pWin, wxRadioButton);
+
+ pRadioButton->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxCheckBox)))
+ {
+ wxCheckBox* pCheckBox = wxDynamicCast(pWin, wxCheckBox);
+
+ pCheckBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxListBox)))
+ {
+ wxListBox* pListBox = wxDynamicCast(pWin, wxListBox);
+
+ pListBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ if (pListBox->GetWindowStyle() & wxLB_OWNERDRAW)
+ Refresh();
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxComboBox)))
+ {
+ wxComboBox* pComboBox = wxDynamicCast(pWin, wxComboBox);
+
+ pComboBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ }
+ return 0;
+ }
+ break;
+
+ case LN_ENTER: /* dups as CBN_EFCHANGE */
+ {
+ HWND hWnd = HWNDFROMMP(lParam);
+ wxWindowOS2* pWin = wxFindWinFromHandle(hWnd);
+
+ if (!pWin)
+ {
+ bProcessed = FALSE;
+ break;
+ }
+ //
+ // Simulate a WM_COMMAND here, as wxWidgets expects all control
+ // button clicks to generate WM_COMMAND msgs, not WM_CONTROL
+ //
+ if (pWin->IsKindOf(CLASSINFO(wxListBox)))
+ {
+ wxListBox* pListBox = wxDynamicCast(pWin, wxListBox);
+
+ pListBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ if (pListBox->GetWindowStyle() & wxLB_OWNERDRAW)
+ Refresh();
+
+ }
+ if (pWin->IsKindOf(CLASSINFO(wxComboBox)))
+ {
+ wxComboBox* pComboBox = wxDynamicCast(pWin, wxComboBox);
+
+ pComboBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+ ,(WXUINT)SHORT1FROMMP(wParam)
+ );
+ }
+ return 0;
+ }
+ break;
+
+ case SPBN_UPARROW:
+ case SPBN_DOWNARROW:
+ case SPBN_CHANGE:
+ {
+ char zVal[10];
+ long lVal;
+
+ ::WinSendMsg( HWNDFROMMP(lParam)
+ ,SPBM_QUERYVALUE
+ ,&zVal
+ ,MPFROM2SHORT( (USHORT)10
+ ,(USHORT)SPBQ_UPDATEIFVALID
+ )
+ );
+ lVal = atol(zVal);
+ bProcessed = OS2OnScroll( wxVERTICAL
+ ,(int)SHORT2FROMMP(wParam)
+ ,(int)lVal
+ ,HWNDFROMMP(lParam)
+ );
+ }
+ break;
+
+ case SLN_SLIDERTRACK:
+ {
+ HWND hWnd = ::WinWindowFromID(GetHWND(), SHORT1FROMMP(wParam));
+ wxWindowOS2* pChild = wxFindWinFromHandle(hWnd);
+
+ if (!pChild)
+ {
+ bProcessed = FALSE;
+ break;
+ }
+ if (pChild->IsKindOf(CLASSINFO(wxSlider)))
+ bProcessed = OS2OnScroll( wxVERTICAL
+ ,(int)SHORT2FROMMP(wParam)
+ ,(int)LONGFROMMP(lParam)
+ ,hWnd
+ );
+ }
+ break;
+ }
+ break;
+
+#if defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
+ case WM_CTLCOLORCHANGE:
+ {
+ bProcessed = HandleCtlColor(&hBrush);
+ }
+ break;
+#endif
+ case WM_ERASEBACKGROUND:
+ //
+ // Returning TRUE to requestw PM to paint the window background
+ // in SYSCLR_WINDOW. We don't really want that
+ //
+ bProcessed = HandleEraseBkgnd((WXHDC)(HPS)wParam);
+ mResult = (MRESULT)(FALSE);
+ break;
+
+ // the return value for this message is ignored
+ case WM_SYSCOLORCHANGE:
+ bProcessed = HandleSysColorChange();
+ break;
+
+ case WM_REALIZEPALETTE:
+ bProcessed = HandlePaletteChanged();
+ break;
+
+ // move all drag and drops to wxDrg
+ case WM_ENDDRAG:
+ bProcessed = HandleEndDrag(wParam);
+ break;
+
+ case WM_INITDLG:
+ bProcessed = HandleInitDialog((WXHWND)(HWND)wParam);
+
+ if ( bProcessed )
+ {
+ // we never set focus from here
+ mResult = (MRESULT)FALSE;
+ }
+ break;
+
+ // wxFrame specific message
+ case WM_MINMAXFRAME:
+ bProcessed = HandleGetMinMaxInfo((PSWP)wParam);
+ break;
+
+ case WM_SYSVALUECHANGED:
+ // TODO: do something
+ mResult = (MRESULT)TRUE;
+ break;
+
+ //
+ // Comparable to WM_SETPOINTER for windows, only for just controls
+ //
+ case WM_CONTROLPOINTER:
+ bProcessed = HandleSetCursor( SHORT1FROMMP(wParam) // Control ID
+ ,(HWND)lParam // Cursor Handle
+ );
+ if (bProcessed )
+ {
+ //
+ // Returning TRUE stops the DefWindowProc() from further
+ // processing this message - exactly what we need because we've
+ // just set the cursor.
+ //
+ mResult = (MRESULT)TRUE;
+ }
+ break;
+
+#if wxUSE_MENUS_NATIVE
+ case WM_MENUEND:
+ if (wxCurrentPopupMenu)
+ {
+ if (GetHmenuOf(wxCurrentPopupMenu) == (HWND)lParam)
+ {
+ // Break out of msg loop in DoPopupMenu
+ ::WinPostMsg((HWND)lParam,WM_COMMAND,wParam,0);
+ }
+ }
+ break;
+#endif // wxUSE_MENUS_NATIVE
+
+ }
+ if (!bProcessed)
+ {
+#ifdef __WXDEBUG__
+ wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
+ wxGetMessageName(uMsg));
+#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
+
+// ----------------------------------------------------------------------------
+// wxWindow <-> HWND map
+// ----------------------------------------------------------------------------
+
+wxWinHashTable *wxWinHandleHash = NULL;
+
+wxWindow* wxFindWinFromHandle(
+ WXHWND hWnd
+)
+{
+ return (wxWindow *)wxWinHandleHash->Get((long)hWnd);
+} // end of wxFindWinFromHandle
+
+void wxAssociateWinWithHandle(
+ HWND hWnd
+, wxWindowOS2* pWin
+)
+{
+ //
+ // Adding NULL hWnd is (first) surely a result of an error and
+ // (secondly) breaks menu command processing
+ //
+ wxCHECK_RET( hWnd != (HWND)NULL,
+ wxT("attempt to add a NULL hWnd to window list ignored") );
+
+
+ wxWindow* pOldWin = wxFindWinFromHandle((WXHWND) hWnd);
+
+ if (pOldWin && (pOldWin != pWin))
+ {
+ wxString str(pWin->GetClassInfo()->GetClassName());
+ wxLogError( "Bug! Found existing HWND %X for new window of class %s"
+ ,(int)hWnd
+ ,(const char*)str
+ );
+ }
+ else if (!pOldWin)
+ {
+ wxWinHandleHash->Put( (long)hWnd
+ ,(wxWindow *)pWin
+ );
+ }
+} // end of wxAssociateWinWithHandle
+
+void wxRemoveHandleAssociation(
+ wxWindowOS2* pWin
+)
+{
+ wxWinHandleHash->Delete((long)pWin->GetHWND());
+} // end of wxRemoveHandleAssociation
+
+//
+// Default destroyer - override if you destroy it in some other way
+// (e.g. with MDI child windows)
+//
+void wxWindowOS2::OS2DestroyWindow()
+{
+}
+
+bool wxWindowOS2::OS2GetCreateWindowCoords(
+ const wxPoint& rPos
+, const wxSize& rSize
+, int& rnX
+, int& rnY
+, int& rnWidth
+, int& rnHeight
+) const
+{
+ bool bNonDefault = FALSE;
+ static const int DEFAULT_Y = 200;
+ static const int DEFAULT_H = 250;
+
+ if (rPos.x == -1)
+ {
+ rnX = rnY = CW_USEDEFAULT;
+ }
+ else
+ {
+ rnX = rPos.x;
+ rnY = rPos.y == -1 ? DEFAULT_Y : rPos.y;
+ bNonDefault = TRUE;
+ }
+ if (rSize.x == -1)
+ {
+ rnWidth = rnHeight = CW_USEDEFAULT;
+ }
+ else
+ {
+ rnWidth = rSize.x;
+ rnHeight = rSize.y == -1 ? DEFAULT_H : rSize.y;
+ bNonDefault = TRUE;
+ }
+ return bNonDefault;
+} // end of wxWindowOS2::OS2GetCreateWindowCoords
+
+WXHWND wxWindowOS2::OS2GetParent() const
+{
+ return m_parent ? m_parent->GetHWND() : NULL;