X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1a4138c79aca299ccd31ab8248918e7910ea20d3..dc8c61bef78e406080de2be91bc6e8d746edb647:/src/os2/window.cpp diff --git a/src/os2/window.cpp b/src/os2/window.cpp index 502e81356e..b0aa9ea547 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: windows.cpp +// Name: src/os2/window.cpp // Purpose: wxWindow // Author: David Webster // Modified by: @@ -14,13 +14,13 @@ // #include "wx/wxprec.h" +#include "wx/window.h" + #ifndef WX_PRECOMP #define INCL_DOS #define INCL_PM #include - #include "wx/window.h" #include "wx/accel.h" - #include "wx/setup.h" #include "wx/menu.h" #include "wx/dc.h" #include "wx/dcclient.h" @@ -44,9 +44,15 @@ #include "wx/statusbr.h" #include "wx/toolbar.h" #include "wx/settings.h" + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/textctrl.h" + #include "wx/menuitem.h" #include #endif +#include "wx/os2/dcclient.h" + #if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" #endif @@ -55,9 +61,6 @@ #include "wx/dnd.h" #endif -#include "wx/menuitem.h" -#include "wx/log.h" - #include "wx/os2/private.h" #if wxUSE_TOOLTIPS @@ -72,12 +75,6 @@ #include "wx/caret.h" #endif // wxUSE_CARET -#include "wx/intl.h" -#include "wx/log.h" - - -#include "wx/textctrl.h" - #include // @@ -126,7 +123,7 @@ QMSG s_currentMsg; #if wxUSE_MENUS_NATIVE -wxMenu* wxCurrentPopupMenu = NULL; +extern wxMenu* wxCurrentPopupMenu; #endif // wxUSE_MENUS_NATIVE // --------------------------------------------------------------------------- @@ -159,8 +156,9 @@ wxWindow* wxFindWinFromHandle(WXHWND hWnd); // // get the current state of SHIFT/CTRL keys // -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 inline bool IsKeyDown(LONG key) {return (::WinGetKeyState(HWND_DESKTOP, key) & 0x8000) != 0; } +static inline bool IsShiftDown() { return IsKeyDown(VK_SHIFT); } +static inline bool IsCtrlDown() { return IsKeyDown(VK_CTRL); } static wxWindow* gpWinBeingCreated = NULL; @@ -172,9 +170,7 @@ static wxWindow* gpWinBeingCreated = NULL; // method #ifdef __WXUNIVERSAL__ IMPLEMENT_ABSTRACT_CLASS(wxWindowOS2, wxWindowBase) -#else // __WXPM__ - IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) -#endif // __WXUNIVERSAL__/__WXPM__ +#endif // __WXUNIVERSAL__ BEGIN_EVENT_TABLE(wxWindowOS2, wxWindowBase) EVT_ERASE_BACKGROUND(wxWindowOS2::OnEraseBackground) @@ -299,7 +295,6 @@ void wxWindowOS2::Init() m_bUseCtl3D = false; m_bMouseInWindow = false; m_bLastKeydownProcessed = false; - m_pChildrenDisabled = NULL; // // wxWnd @@ -337,7 +332,7 @@ void wxWindowOS2::Init() // wxWindowOS2::~wxWindowOS2() { - m_isBeingDeleted = true; + SendDestroyEvent(); for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent()) { @@ -355,13 +350,14 @@ wxWindowOS2::~wxWindowOS2() if (m_hWnd) { if(!::WinDestroyWindow(GetHWND())) + { wxLogLastError(wxT("DestroyWindow")); + } // // remove hWnd <-> wxWindow association // wxRemoveHandleAssociation(this); } - delete m_pChildrenDisabled; } // end of wxWindowOS2::~wxWindowOS2 // real construction (Init() must have been called before!) @@ -388,7 +384,7 @@ bool wxWindowOS2::Create( wxWindow* pParent, // static box // wxASSERT_MSG( !wxDynamicCast(pParent, wxStaticBox), - _T("wxStaticBox can't be used as a window parent!") ); + wxT("wxStaticBox can't be used as a window parent!") ); #endif // wxUSE_STATBOX // Ensure groupbox backgrounds are painted @@ -458,7 +454,7 @@ bool wxWindowOS2::Create( wxWindow* pParent, void wxWindowOS2::SetFocus() { HWND hWnd = GetHwnd(); - wxCHECK_RET( hWnd, _T("can't set focus to invalid window") ); + wxCHECK_RET( hWnd, wxT("can't set focus to invalid window") ); if (hWnd) ::WinSetFocus(HWND_DESKTOP, hWnd); @@ -483,70 +479,12 @@ wxWindow* wxWindowBase::DoFindFocus() return NULL; } // wxWindowBase::DoFindFocus -bool wxWindowOS2::Enable( bool bEnable ) +void wxWindowOS2::DoEnable( bool bEnable ) { - if (!wxWindowBase::Enable(bEnable)) - return false; - HWND hWnd = GetHwnd(); - if ( hWnd ) ::WinEnableWindow(hWnd, (BOOL)bEnable); - - // - // The logic below doesn't apply to the top level windows -- otherwise - // showing a modal dialog would result in total greying out (and ungreying - // out later) of everything which would be really ugly - // - if (IsTopLevel()) - return true; - - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - - while (node) - { - wxWindow* pChild = node->GetData(); - - if (bEnable) - { - // - // Enable the child back unless it had been disabled before us - // - if (!m_pChildrenDisabled || !m_pChildrenDisabled->Find(pChild)) - pChild->Enable(); - } - else // we're being disabled - { - if (pChild->IsEnabled()) - { - // - // Disable it as children shouldn't stay enabled while the - // parent is not - // - pChild->Disable(); - } - else // child already disabled, remember it - { - // - // Have we created the list of disabled children already? - // - if (!m_pChildrenDisabled) - m_pChildrenDisabled = new wxWindowList; - m_pChildrenDisabled->Append(pChild); - } - } - node = node->GetNext(); - } - if (bEnable && m_pChildrenDisabled) - { - // - // We don't need this list any more, don't keep unused memory - // - delete m_pChildrenDisabled; - m_pChildrenDisabled = NULL; - } - return true; -} // end of wxWindowOS2::Enable +} bool wxWindowOS2::Show( bool bShow ) { @@ -574,15 +512,15 @@ void wxWindowOS2::Lower() ::WinSetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE); } // end of wxWindowOS2::Lower -void wxWindowOS2::SetTitle( const wxString& rTitle ) +void wxWindowOS2::SetLabel( const wxString& label ) { - ::WinSetWindowText(GetHwnd(), (PSZ)rTitle.c_str()); -} // end of wxWindowOS2::SetTitle + ::WinSetWindowText(GetHwnd(), label.c_str()); +} // end of wxWindowOS2::SetLabel -wxString wxWindowOS2::GetTitle() const +wxString wxWindowOS2::GetLabel() const { return wxGetWindowText(GetHWND()); -} // end of wxWindowOS2::GetTitle +} // end of wxWindowOS2::GetLabel void wxWindowOS2::DoCaptureMouse() { @@ -593,7 +531,7 @@ void wxWindowOS2::DoCaptureMouse() ::WinSetCapture(HWND_DESKTOP, hWnd); m_bWinCaptured = true; } -} // end of wxWindowOS2::GetTitle +} // end of wxWindowOS2::DoCaptureMouse void wxWindowOS2::DoReleaseMouse() { @@ -607,7 +545,7 @@ void wxWindowOS2::DoReleaseMouse() /* static */ wxWindow* wxWindowBase::GetCapture() { HWND hwnd = ::WinQueryCapture(HWND_DESKTOP); - return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL; + return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : NULL; } // end of wxWindowBase::GetCapture bool wxWindowOS2::SetFont( const wxFont& rFont ) @@ -633,7 +571,7 @@ bool wxWindowOS2::SetCursor( const wxCursor& rCursor) return false; } - if ( m_cursor.Ok() ) { + if ( m_cursor.IsOk() ) { HWND hWnd = GetHwnd(); POINTL vPoint; RECTL vRect; @@ -725,6 +663,10 @@ void wxWindowOS2::SetScrollbar( int nOrient, int nOldRange = nRange - nThumbVisible; int nRange1 = nOldRange; int nPageSize = nThumbVisible; + int nVSBWidth = wxSystemSettingsNative::GetMetric(wxSYS_VSCROLL_X, + this); + int nHSBHeight = wxSystemSettingsNative::GetMetric(wxSYS_HSCROLL_Y, + this); SBCDATA vInfo; ULONG ulStyle = WS_VISIBLE | WS_SYNCPAINT; @@ -786,8 +728,8 @@ void wxWindowOS2::SetScrollbar( int nOrient, ,ulStyle ,vSwp.x ,vSwp.y - ,vSwp.cx - 20 - ,20 + ,vSwp.cx - nVSBWidth + ,nHSBHeight ,hWnd ,HWND_TOP ,60000 @@ -804,18 +746,19 @@ void wxWindowOS2::SetScrollbar( int nOrient, // origin, not the frame's client window origin. // The starting x position is the same as the starting x position // of the owner, but in terms of the parent frame. - // The starting y position is 20 pels below the origin of the - // owner in terms of the parent frame. - // The horz bar is the same width as the owner and 20 pels high. + // The starting y position is wxSYS_HSCROLL_Y pels below the + // origin of the owner in terms of the parent frame. + // The horz bar is the same width as the owner and wxSYS_HSCROLL_Y + // pels high. // if (nRange1 >= nThumbVisible) { ::WinSetWindowPos( m_hWndScrollBarHorz ,HWND_TOP ,vSwp.x + vSwpOwner.x - ,(vSwp.y + vSwpOwner.y) - 20 + ,(vSwp.y + vSwpOwner.y) - nHSBHeight ,vSwpOwner.cx - ,20 + ,nHSBHeight ,SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER ); ::WinSendMsg( m_hWndScrollBarHorz @@ -856,10 +799,10 @@ void wxWindowOS2::SetScrollbar( int nOrient, ,WC_SCROLLBAR ,(PSZ)NULL ,ulStyle - ,vSwp.x + vSwp.cx - 20 - ,vSwp.y + 20 - ,20 - ,vSwp.cy - 20 + ,vSwp.x + vSwp.cx - nVSBWidth + ,vSwp.y + nHSBHeight + ,nVSBWidth + ,vSwp.cy - nHSBHeight ,hWnd ,HWND_TOP ,60001 @@ -882,7 +825,7 @@ void wxWindowOS2::SetScrollbar( int nOrient, // position of the scrollbar relative to the parent frame (the vert // scrollbar is on the right and starts at the bottom of the // owner window). - // It is 20 pels wide and the same height as the owner. + // It is wxSYS_VSCROLL_X pels wide and the same height as the owner. // if (nRange1 >= nThumbVisible) { @@ -890,7 +833,7 @@ void wxWindowOS2::SetScrollbar( int nOrient, ,HWND_TOP ,vSwp.x + vSwpOwner.x + vSwpOwner.cx ,vSwp.y + vSwpOwner.y - ,20 + ,nVSBWidth ,vSwpOwner.cy ,SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW ); @@ -1141,17 +1084,15 @@ void wxWindowOS2::OnIdle( ,vPoint.y ,nState ); - (void)GetEventHandler()->ProcessEvent(rEvent); + (void)HandleWindowEvent(rEvent); } } - if (wxUpdateUIEvent::CanUpdate(this)) - UpdateWindowUI(wxUPDATE_UI_FROMIDLE); } // end of wxWindowOS2::OnIdle // // Set this window to be the child of 'parent'. // -bool wxWindowOS2::Reparent( wxWindow* pParent) +bool wxWindowOS2::Reparent( wxWindowBase* pParent) { if (!wxWindowBase::Reparent(pParent)) return false; @@ -1168,12 +1109,12 @@ void wxWindowOS2::Update() ::WinUpdateWindow(GetHwnd()); } // end of wxWindowOS2::Update -void wxWindowOS2::Freeze() +void wxWindowOS2::DoFreeze() { ::WinSendMsg(GetHwnd(), WM_VRNDISABLED, (MPARAM)0, (MPARAM)0); } // end of wxWindowOS2::Freeze -void wxWindowOS2::Thaw() +void wxWindowOS2::DoThaw() { ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0); @@ -1294,7 +1235,10 @@ void wxWindowOS2::DoGetPosition( , int* pY ) const { - HWND hWnd = GetHwnd(); + // + // Return parameters assume wxWidgets coordinate system + // + HWND hWnd; SWP vSwp; POINTL vPoint; wxWindow* pParent = GetParent(); @@ -1304,17 +1248,30 @@ void wxWindowOS2::DoGetPosition( // 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, + // use 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. + // wxWindow coordinates, i.e. 0,0 is the TOP left. // + if (IsKindOf(CLASSINFO(wxFrame))) + { + wxFrame* pFrame = wxDynamicCast(this, wxFrame); + hWnd = pFrame->GetFrame(); + } + else + hWnd = GetHwnd(); + ::WinQueryWindowPos(hWnd, &vSwp); vPoint.x = vSwp.x; vPoint.y = vSwp.y; + // We need to convert to wxWidgets coordinates + int vHeight; + DoGetSize(NULL,&vHeight); + wxWindow* pWindow = wxDynamicCast(this,wxWindow); + vPoint.y = pWindow->GetOS2ParentHeight(pParent) - vPoint.y - vHeight; + // // 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). @@ -1446,18 +1403,12 @@ void wxWindowOS2::DoMoveWindow( , int nHeight ) { + // + // Input parameters assume wxWidgets coordinate system + // 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; + HWND hWnd = GetHwnd(); if (pParent && !IsKindOf(CLASSINFO(wxDialog))) { @@ -1487,64 +1438,26 @@ void wxWindowOS2::DoMoveWindow( 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); + hWnd = pFrame->GetFrame(); + ::WinQueryWindowRect(hWnd, &vRect); + ::WinMapWindowPoints(hWnd, HWND_DESKTOP, (PPOINTL)&vRect, 2); vFRect = vRect; - ::WinCalcFrameRect(hWndFrame, &vRect, TRUE); + ::WinCalcFrameRect(hWnd, &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 - ); - } - } + // Input values refer to the window position relative to its parent + // which may be the Desktop so we need to calculate + // the new frame values to keep the wxWidgets frame origin constant + nY -= nHeightFrameDelta; + nWidth += nWidthFrameDelta; + nHeight += nHeightFrameDelta; } - - ::WinSetWindowPos( GetHwnd() + ::WinSetWindowPos( hWnd ,HWND_TOP ,(LONG)nX ,(LONG)nY @@ -1556,17 +1469,15 @@ void wxWindowOS2::DoMoveWindow( // // Uninitialized // - ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp); + ::WinQueryWindowPos(hWnd, &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 + // be scrolled is the owner (gets the scroll notifications). 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 + // by the size of the scroll bar widths 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 @@ -1579,20 +1490,24 @@ void wxWindowOS2::DoMoveWindow( { int nAdjustWidth = 0; int nAdjustHeight = 0; + int nHSBHeight = wxSystemSettingsNative::GetMetric(wxSYS_HSCROLL_Y, + this); + int nVSBWidth = wxSystemSettingsNative::GetMetric(wxSYS_VSCROLL_X, + this); SWP vSwpScroll; if (GetScrollBarHorz() == NULLHANDLE || !WinIsWindowShowing(GetScrollBarHorz())) nAdjustHeight = 0L; else - nAdjustHeight = 20L; + nAdjustHeight = nHSBHeight; if (GetScrollBarVert() == NULLHANDLE || !WinIsWindowShowing(GetScrollBarVert())) nAdjustWidth = 0L; else - nAdjustWidth = 20L; - ::WinQueryWindowPos(GetHWND(), &vSwpScroll); - ::WinSetWindowPos( GetHWND() + nAdjustWidth = nVSBWidth; + ::WinQueryWindowPos(hWnd, &vSwpScroll); + ::WinSetWindowPos( hWnd ,HWND_TOP ,vSwpScroll.x ,vSwpScroll.y + nAdjustHeight @@ -1600,19 +1515,9 @@ void wxWindowOS2::DoMoveWindow( ,vSwpScroll.cy - nAdjustHeight ,SWP_MOVE | SWP_SIZE ); - nYDiff -= nAdjustHeight; } - MoveChildren(nYDiff); - ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp); + ::WinQueryWindowPos(hWnd, &m_vWinSwp); } -#if 0 - // FIXME: By my logic, the next line should be needed as it moves child - // windows when resizing the parent (see comment at beginning of - // function). However, this seems to cause lots of problems. At - // least, e.g. the grid sample almost works with this line - // commented out but crashes badly with it. - MoveChildren(nHeightDelta); -#endif } // end of wxWindowOS2::DoMoveWindow // @@ -1631,6 +1536,10 @@ void wxWindowOS2::DoSetSize( int nX, int nHeight, int nSizeFlags ) { + // + // Input & output parameters assume wxWidgets coordinate system + // + // // Get the current size and position... // @@ -1646,12 +1555,7 @@ void wxWindowOS2::DoSetSize( int nX, // // ... 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 && + if (nX == nCurrentX && nY == nCurrentY && nWidth == nCurrentWidth && nHeight == nCurrentHeight) { return; @@ -1703,55 +1607,20 @@ void wxWindowOS2::DoSetSize( int nX, 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; + // + // nX & nY assume wxWidgets coordinate system + // + int nX; + int nY; - GetPosition(&nX, &nY); - nActualWidth = nWidth; - nActualHeight = nHeight; + GetPosition(&nX, &nY); - vPoint.x = nX; - vPoint.y = nY; - } - DoMoveWindow( vPoint.x, vPoint.y, nActualWidth, nActualHeight ); + DoMoveWindow( nX, nY, nWidth, nHeight ); wxSize size( nWidth, nHeight ); wxSizeEvent vEvent( size, m_windowId ); vEvent.SetEventObject(this); - GetEventHandler()->ProcessEvent(vEvent); + HandleWindowEvent(vEvent); } // end of wxWindowOS2::DoSetClientSize // --------------------------------------------------------------------------- @@ -1790,12 +1659,12 @@ int wxWindowOS2::GetCharWidth() const return(vFontMetrics.lAveCharWidth); } // end of wxWindowOS2::GetCharWidth -void wxWindowOS2::GetTextExtent( const wxString& rString, - int* pX, - int* pY, - int* pDescent, - int* pExternalLeading, - const wxFont* WXUNUSED(pTheFont) ) const +void wxWindowOS2::DoGetTextExtent( const wxString& rString, + int* pX, + int* pY, + int* pDescent, + int* pExternalLeading, + const wxFont* WXUNUSED(pTheFont) ) const { POINTL avPoint[TXTBOX_COUNT]; POINTL vPtMin; @@ -1804,25 +1673,22 @@ void wxWindowOS2::GetTextExtent( const wxString& rString, int l; FONTMETRICS vFM; // metrics structure BOOL bRc = FALSE; - char* pStr; HPS hPS; hPS = ::WinGetPS(GetHwnd()); - l = rString.Length(); + 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 - ); + bRc = ::GpiQueryTextBox( hPS, + l, + (char*) rString.wx_str(), + TXTBOX_COUNT,// return maximum information + avPoint // array of coordinates points + ); if (bRc) { vPtMin.x = avPoint[0].x; @@ -1882,7 +1748,7 @@ void wxWindowOS2::GetTextExtent( const wxString& rString, *pExternalLeading = 0; } ::WinReleasePS(hPS); -} // end of wxWindow::GetTextExtent +} // end of wxWindow::DoGetTextExtent bool wxWindowOS2::IsMouseInWindow() const { @@ -1910,9 +1776,7 @@ bool wxWindowOS2::IsMouseInWindow() const // --------------------------------------------------------------------------- // #if wxUSE_MENUS_NATIVE -bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, - int nX, - int nY ) +bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY ) { HWND hWndOwner = GetHwnd(); HWND hWndParent = GetHwnd(); @@ -1920,11 +1784,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, bool bIsWaiting = true; int nHeight; - // Protect against recursion - if (wxCurrentPopupMenu) - return false; - - pMenu->SetInvokingWindow(this); pMenu->UpdateUI(); if ( nX == -1 && nY == -1 ) @@ -1940,7 +1799,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, DoGetSize(0,&nHeight); nY = nHeight - nY; } - wxCurrentPopupMenu = pMenu; ::WinPopupMenu( hWndParent ,hWndOwner @@ -1961,8 +1819,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg); } - wxCurrentPopupMenu = NULL; - pMenu->SetInvokingWindow(NULL); return true; } // end of wxWindowOS2::DoPopupMenu #endif // wxUSE_MENUS_NATIVE @@ -2094,9 +1950,13 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg ) } else { - wxButton* pBtn = wxDynamicCast( GetDefaultItem() - ,wxButton - ); + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + wxButton* pBtn = NULL; + + if (tlw) + { + pBtn = wxDynamicCast(tlw->GetDefaultItem(), wxButton); + } if (pBtn && pBtn->IsEnabled()) { @@ -2133,7 +1993,7 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg ) vEvent.SetWindowChange(bWindowChange); vEvent.SetEventObject(this); - if (GetEventHandler()->ProcessEvent(vEvent)) + if (HandleWindowEvent(vEvent)) { wxButton* pBtn = wxDynamicCast(FindFocus(), wxButton); @@ -2465,9 +2325,6 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, case WM_BUTTON3MOTIONEND: case WM_BUTTON3MOTIONSTART: { - if (uMsg == WM_BUTTON1DOWN && AcceptsFocus()) - SetFocus(); - short nX = LOWORD(wParam); short nY = HIWORD(wParam); @@ -2490,7 +2347,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, ); if (!pWin->IsOfStandardClass()) { - if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() ) + if (uMsg == WM_BUTTON1DOWN && pWin->CanAcceptFocus() ) pWin->SetFocus(); } bProcessed = pWin->HandleMouseEvent( uMsg @@ -2687,7 +2544,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, (pPage->ulPageIdNew > 0L && pPage->ulPageIdCur > 0L)) { wxWindowOS2* pWin = wxFindWinFromHandle(pPage->hwndBook); - wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED + wxBookCtrlEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED ,(int)SHORT1FROMMP(wParam) ,(int)pPage->ulPageIdNew ,(int)pPage->ulPageIdCur @@ -2713,6 +2570,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, } break; + case CBN_LBSELECT: case BN_CLICKED: // Dups as LN_SELECT and CBN_LBSELECT { HWND hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam)); @@ -2769,11 +2627,19 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, ,(WXWORD)SHORT1FROMMP(wParam) ); } + if (pWin->IsKindOf(CLASSINFO(wxChoice))) + { + wxChoice* pChoice = wxDynamicCast(pWin, wxChoice); + + pChoice->OS2Command( (WXUINT)SHORT2FROMMP(wParam) + ,(WXWORD)SHORT1FROMMP(wParam) + ); + } return 0; } // break; - case LN_ENTER: /* dups as CBN_EFCHANGE */ + case LN_ENTER: { HWND hWnd = HWNDFROMMP(lParam); wxWindowOS2* pWin = wxFindWinFromHandle(hWnd); @@ -2977,16 +2843,16 @@ void wxAssociateWinWithHandle( 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( _T("Bug! Found existing HWND %X for new window of class %s") - ,(int)hWnd - ,str.c_str() + wxString Newstr(pWin->GetClassInfo()->GetClassName()); + wxString Oldstr(pOldWin->GetClassInfo()->GetClassName()); + wxLogError( wxT("Bug! New window of class %s has same HWND %X as old window of class %s"), + Newstr.c_str(), + (int)hWnd, + Oldstr.c_str() ); } else if (!pOldWin) @@ -3067,6 +2933,7 @@ bool wxWindowOS2::OS2Create( PSZ zClass, long lControlId = 0L; wxWindowCreationHook vHook(this); wxString sClassName((wxChar*)zClass); + wxString sTitle(zTitle ? zTitle : wxEmptyString); OS2GetCreateWindowCoords( rPos ,rSize @@ -3094,8 +2961,8 @@ bool wxWindowOS2::OS2Create( PSZ zClass, sClassName += wxT("NR"); } m_hWnd = (WXHWND)::WinCreateWindow( (HWND)OS2GetParent() - ,(PSZ)sClassName.c_str() - ,(PSZ)(zTitle ? zTitle : wxEmptyString) + ,sClassName.c_str() + ,sTitle.c_str() ,(ULONG)dwStyle ,(LONG)0L ,(LONG)0L @@ -3116,7 +2983,7 @@ bool wxWindowOS2::OS2Create( PSZ zClass, SubclassWin(m_hWnd); SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - m_backgroundColour.Set(wxString(wxT("GREY"))); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); LONG lColor = (LONG)m_backgroundColour.GetPixel(); @@ -3128,7 +2995,7 @@ bool wxWindowOS2::OS2Create( PSZ zClass, { vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str()); + wxLogError(wxT("Error creating frame. Error: %s\n"), sError.c_str()); return false; } SetSize( nX @@ -3137,7 +3004,7 @@ bool wxWindowOS2::OS2Create( PSZ zClass, ,nHeight ); return true; -} // end of WinGuiBase_Window::OS2Create +} // end of wxWindowOS2::OS2Create // =========================================================================== // OS2 PM message handlers @@ -3152,7 +3019,7 @@ bool wxWindowOS2::HandleCreate( WXLPCREATESTRUCT WXUNUSED(vCs), { wxWindowCreateEvent vEvent((wxWindow*)this); - (void)GetEventHandler()->ProcessEvent(vEvent); + (void)HandleWindowEvent(vEvent); *pbMayCreate = true; return true; } // end of wxWindowOS2::HandleCreate @@ -3161,17 +3028,13 @@ bool wxWindowOS2::HandleDestroy() { wxWindowDestroyEvent vEvent((wxWindow*)this); vEvent.SetId(GetId()); - (void)GetEventHandler()->ProcessEvent(vEvent); + (void)HandleWindowEvent(vEvent); // // Delete our drop target if we've got one // #if wxUSE_DRAG_AND_DROP - if (m_dropTarget != NULL) - { - delete m_dropTarget; - m_dropTarget = NULL; - } + wxDELETE(m_dropTarget); #endif // wxUSE_DRAG_AND_DROP // @@ -3200,7 +3063,7 @@ bool wxWindowOS2::HandleActivate( ,m_windowId ); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleActivate bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) @@ -3210,7 +3073,7 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) // purposes that we got it // wxChildFocusEvent vEventFocus((wxWindow *)this); - (void)GetEventHandler()->ProcessEvent(vEventFocus); + (void)HandleWindowEvent(vEventFocus); #if wxUSE_CARET // @@ -3234,7 +3097,7 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) wxFocusEvent vEvent(wxEVT_SET_FOCUS, m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleSetFocus bool wxWindowOS2::HandleKillFocus( WXHWND hWnd ) @@ -3281,7 +3144,7 @@ bool wxWindowOS2::HandleKillFocus( WXHWND hWnd ) // wxFindWinFromHandle() may return NULL, it is ok // vEvent.SetWindow(wxFindWinFromHandle(hWnd)); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleKillFocus // --------------------------------------------------------------------------- @@ -3296,7 +3159,7 @@ bool wxWindowOS2::HandleShow( wxShowEvent vEvent(GetId(), bShow); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleShow bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) ) @@ -3304,7 +3167,7 @@ bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) ) wxInitDialogEvent vEvent(GetId()); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleInitDialog bool wxWindowOS2::HandleEndDrag(WXWPARAM WXUNUSED(wParam)) @@ -3331,7 +3194,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, WXDRAWITEMSTRUCT* pItemStruct ) { #if wxUSE_OWNER_DRAWN - wxDC vDc; + wxClientDC vDc(this); #if wxUSE_MENUS_NATIVE // @@ -3350,8 +3213,10 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, ,pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft ,pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom ); - vDc.SetHDC( hDC, false ); - vDc.SetHPS( pMeasureStruct->hps ); + + wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl(); + impl->SetHDC( hDC, false ); + impl->SetHPS( pMeasureStruct->hps ); // // Load the wxWidgets Pallete and set to RGB mode // @@ -3365,7 +3230,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, { vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - wxLogError(_T("Unable to set current color table. Error: %s\n"), sError.c_str()); + wxLogError(wxT("Unable to set current color table (1). Error: %s\n"), sError.c_str()); } // // Set the color table to RGB mode @@ -3380,7 +3245,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, { vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - wxLogError(_T("Unable to set current color table. Error: %s\n"), sError.c_str()); + wxLogError(wxT("Unable to set current color table (2). Error: %s\n"), sError.c_str()); } wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); @@ -3541,7 +3406,7 @@ bool wxWindowOS2::HandleSysColorChange() wxSysColourChangedEvent vEvent; vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleSysColorChange bool wxWindowOS2::HandleCtlColor( WXHBRUSH* WXUNUSED(phBrush) ) @@ -3574,7 +3439,7 @@ bool wxWindowOS2::HandlePaletteChanged() vEvent.SetEventObject(this); vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandlePaletteChanged // @@ -3598,7 +3463,7 @@ void wxWindowOS2::OnSysColourChanged( wxSysColourChangedEvent vEvent; rEvent.SetEventObject(pWin); - pWin->GetEventHandler()->ProcessEvent(vEvent); + pWin->HandleWindowEvent(vEvent); } node = node->GetNext(); } @@ -3612,7 +3477,7 @@ void wxWindow::OnPaint ( wxPaintEvent& rEvent ) { - HDC hDC = (HDC)wxPaintDC::FindDCInCache((wxWindow*) rEvent.GetEventObject()); + HDC hDC = (HDC)wxPaintDCImpl::FindDCInCache((wxWindow*) rEvent.GetEventObject()); if (hDC != 0) { @@ -3640,15 +3505,10 @@ bool wxWindowOS2::HandlePaint() wxLogLastError(wxT("CreateRectRgn")); return false; } - // Get all the rectangles from the region, convert the individual // rectangles to "the other" coordinate system and reassemble a // region from the rectangles, to be feed into m_updateRegion. // - // FIXME: This is a bad hack since OS/2 API specifies that rectangles - // passed into GpiSetRegion must not have Bottom > Top, - // however, at first sight, it _seems_ to work nonetheless. - // RGNRECT vRgnData; PRECTL pUpdateRects = NULL; vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT; @@ -3678,18 +3538,17 @@ bool wxWindowOS2::HandlePaint() { int rectHeight; rectHeight = pUpdateRects[i].yTop - pUpdateRects[i].yBottom; - pUpdateRects[i].yTop = height - pUpdateRects[i].yTop; - pUpdateRects[i].yBottom = pUpdateRects[i].yTop + rectHeight; + pUpdateRects[i].yBottom = height - pUpdateRects[i].yTop; + pUpdateRects[i].yTop = pUpdateRects[i].yBottom + rectHeight; } ::GpiSetRegion(hPS, hRgn, vRgnData.crc, pUpdateRects); delete [] pUpdateRects; } } - m_updateRegion = wxRegion(hRgn, hPS); vEvent.SetEventObject(this); - bProcessed = GetEventHandler()->ProcessEvent(vEvent); + bProcessed = HandleWindowEvent(vEvent); if (!bProcessed && IsKindOf(CLASSINFO(wxPanel)) && @@ -3803,27 +3662,26 @@ bool wxWindowOS2::HandleEraseBkgnd( WXHDC hDC ) if (vSwp.fl & SWP_MINIMIZE) return true; - wxDC vDC; - - vDC.m_hPS = (HPS)hDC; // this is really a PS - vDC.SetWindow((wxWindow*)this); - vDC.BeginDrawing(); + wxClientDC vDC(this); + wxPMDCImpl *impl = (wxPMDCImpl*) vDC.GetImpl(); + impl->SetHDC(hDC); + impl->SetHPS((HPS)hDC); // this is really a PS wxEraseEvent vEvent(m_windowId, &vDC); vEvent.SetEventObject(this); - rc = GetEventHandler()->ProcessEvent(vEvent); + rc = HandleWindowEvent(vEvent); - vDC.EndDrawing(); - vDC.m_hPS = NULLHANDLE; + impl->SetHPS(NULLHANDLE); return true; } // end of wxWindowOS2::HandleEraseBkgnd void wxWindowOS2::OnEraseBackground(wxEraseEvent& rEvent) { RECTL vRect; - HPS hPS = rEvent.GetDC()->GetHPS(); + wxPMDCImpl *impl = (wxPMDCImpl*) rEvent.GetDC()->GetImpl(); + HPS hPS = impl->GetHPS(); APIRET rc; LONG lColor = m_backgroundColour.GetPixel(); @@ -3840,7 +3698,7 @@ bool wxWindowOS2::HandleMinimize() wxIconizeEvent vEvent(m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleMinimize bool wxWindowOS2::HandleMaximize() @@ -3848,7 +3706,7 @@ bool wxWindowOS2::HandleMaximize() wxMaximizeEvent vEvent(m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleMaximize bool wxWindowOS2::HandleMove( int nX, int nY ) @@ -3857,7 +3715,7 @@ bool wxWindowOS2::HandleMove( int nX, int nY ) wxMoveEvent vEvent(pt, m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleMove bool wxWindowOS2::HandleSize( int nWidth, @@ -3868,7 +3726,7 @@ bool wxWindowOS2::HandleSize( int nWidth, wxSizeEvent vEvent(sz, m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleSize bool wxWindowOS2::HandleGetMinMaxInfo( PSWP pSwp ) @@ -3878,25 +3736,15 @@ bool wxWindowOS2::HandleGetMinMaxInfo( PSWP pSwp ) switch(pSwp->fl) { case SWP_MAXIMIZE: -#if !(defined(__WATCOMC__) && __WATCOMC__ < 1240 ) -// Open Watcom 1.3 had incomplete headers -// that's reported and should be fixed for OW 1.4 ::WinGetMaxPosition(GetHwnd(), pSwp); m_maxWidth = pSwp->cx; m_maxHeight = pSwp->cy; -#endif break; case SWP_MINIMIZE: -#if !(defined(__WATCOMC__) && __WATCOMC__ < 1240 ) -// Open Watcom 1.3 had incomplete headers -// that's reported and should be fixed for OW 1.4 ::WinGetMinPosition(GetHwnd(), pSwp, &vPoint); m_minWidth = pSwp->cx; m_minHeight = pSwp->cy; -#else - wxUnusedVar(vPoint); -#endif break; default: @@ -3955,7 +3803,7 @@ bool wxWindowOS2::HandleSysCommand( WXWPARAM wParam, // --------------------------------------------------------------------------- // mouse events // --------------------------------------------------------------------------- -//TODO!!! check against MSW +//TODO: check against MSW void wxWindowOS2::InitMouseEvent( wxMouseEvent& rEvent , int nX @@ -3971,12 +3819,9 @@ void wxWindowOS2::InitMouseEvent( rEvent.m_shiftDown = ((uFlags & KC_SHIFT) != 0); rEvent.m_controlDown = ((uFlags & KC_CTRL) != 0); rEvent.m_altDown = ((uFlags & KC_ALT) != 0); - rEvent.m_leftDown = (::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & - 0x8000) != 0; - rEvent.m_middleDown = (::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & - 0x8000) != 0; - rEvent.m_rightDown = (::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & - 0x8000) != 0; + rEvent.m_leftDown = IsKeyDown(VK_BUTTON1); + rEvent.m_middleDown = IsKeyDown(VK_BUTTON3); + rEvent.m_rightDown = IsKeyDown(VK_BUTTON2); rEvent.SetTimestamp(s_currentMsg.time); rEvent.SetEventObject(this); rEvent.SetId(GetId()); @@ -4026,7 +3871,7 @@ bool wxWindowOS2::HandleMouseEvent( WXUINT uMsg, ,uFlags ); - bProcessed = GetEventHandler()->ProcessEvent(vEvent); + bProcessed = HandleWindowEvent(vEvent); if (!bProcessed) { HPOINTER hCursor = (HPOINTER)GetCursor().GetHCURSOR(); @@ -4060,7 +3905,7 @@ bool wxWindowOS2::HandleMouseMove( int nX, ,uFlags ); - (void)GetEventHandler()->ProcessEvent(vEvent); + (void)HandleWindowEvent(vEvent); } return HandleMouseEvent( WM_MOUSEMOVE ,nX @@ -4182,7 +4027,7 @@ bool wxWindowOS2::HandleChar( WXWPARAM WXUNUSED(wParam), vEvent.m_controlDown = true; } - return (GetEventHandler()->ProcessEvent(vEvent)); + return (HandleWindowEvent(vEvent)); } bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam, @@ -4206,7 +4051,7 @@ bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam, ,(MPARAM)wParam )); - if (GetEventHandler()->ProcessEvent(vEvent)) + if (HandleWindowEvent(vEvent)) { return true; } @@ -4235,7 +4080,7 @@ bool wxWindowOS2::HandleKeyUp( WXWPARAM wParam, ,(MPARAM)wParam )); - if (GetEventHandler()->ProcessEvent(vEvent)) + if (HandleWindowEvent(vEvent)) return true; } return false; @@ -4301,91 +4146,12 @@ bool wxWindowOS2::OS2OnScroll( int nOrientation, default: return false; } - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::OS2OnScroll -void wxWindowOS2::MoveChildren( - int nDiff -) -{ - // - // We want to handle top levels ourself, manually - // - if (!IsTopLevel() && GetAutoLayout()) - { - Layout(); - } - else - { - SWP vSwp; - - for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - node; - node = node->GetNext()) - { - wxWindow* pWin = node->GetData(); - - ::WinQueryWindowPos( GetHwndOf(pWin) - ,&vSwp - ); - // Actually, only move children that already are placed on the - // frame, not ones which are still at wxDefaultCoord. - if (vSwp.y == wxDefaultCoord) - continue; - 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 - ); - ::WinQueryWindowPos(GetHwndOf(pWin), pWin->GetSwp()); - 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() - ); - } - } - } - Refresh(); -} // 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 +// pain. There are three situations we must deal with in determining // the OS2 to wxWidgets Y coordinate. // // 1) The controls are created in a dialog. @@ -4416,11 +4182,13 @@ void wxWindowOS2::MoveChildren( // int wxWindowOS2::GetOS2ParentHeight( wxWindowOS2* pParent ) { + if (pParent) + { // // Case 1 // - if (pParent->IsKindOf(CLASSINFO(wxDialog))) - return(pParent->GetClientSize().y); + if (pParent->IsKindOf(CLASSINFO(wxDialog))) + return(pParent->GetClientSize().y); // // Case 2 -- if we are one of the separately built standard Frame @@ -4428,40 +4196,43 @@ int wxWindowOS2::GetOS2ParentHeight( wxWindowOS2* pParent ) // 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)) - ) + else if (pParent->IsKindOf(CLASSINFO(wxFrame))) { - if (IsKindOf(CLASSINFO(wxToolBar))) + if (IsKindOf(CLASSINFO(wxStatusBar)) || + IsKindOf(CLASSINFO(wxMenuBar)) || + IsKindOf(CLASSINFO(wxToolBar)) + ) { - wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame); + if (IsKindOf(CLASSINFO(wxToolBar))) + { + wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame); - if (pFrame->GetToolBar() == this) - return(pParent->GetSize().y); + if (pFrame->GetToolBar() == this) + return(pParent->GetSize().y); + else + return(pParent->GetClientSize().y); + } else - return(pParent->GetClientSize().y); + return(pParent->GetSize().y); } else - return(pParent->GetSize().y); + return(pParent->GetClientSize().y); } + // + // Case -- 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 return(pParent->GetClientSize().y); } - // - // Case -- 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 - // { - - return(pParent->GetClientSize().y); - - // } + else // We must be a child of the screen + { + int nHeight; + wxDisplaySize(NULL,&nHeight); + return(nHeight); + } } // end of wxWindowOS2::GetOS2ParentHeight // @@ -4535,8 +4306,8 @@ int wxCharCodeOS2ToWX( case VK_CTRL: nId = WXK_CONTROL; break; case VK_PAUSE: nId = WXK_PAUSE; break; case VK_SPACE: nId = WXK_SPACE; break; - case VK_PAGEUP: nId = WXK_PRIOR; break; - case VK_PAGEDOWN: nId = WXK_NEXT; break; + case VK_PAGEUP: nId = WXK_PAGEUP; break; + case VK_PAGEDOWN: nId = WXK_PAGEDOWN; break; case VK_ESC: nId = WXK_ESCAPE; break; case VK_END: nId = WXK_END; break; case VK_HOME : nId = WXK_HOME; break; @@ -4598,15 +4369,16 @@ int wxCharCodeWXToOS2( int nId, { int nKeySym = 0; - *bIsVirtual = true; + if ( bIsVirtual ) + *bIsVirtual = true; switch (nId) { case WXK_CLEAR: nKeySym = VK_CLEAR; break; case WXK_SHIFT: nKeySym = VK_SHIFT; break; case WXK_CONTROL: nKeySym = VK_CTRL; break; case WXK_PAUSE: nKeySym = VK_PAUSE; break; - case WXK_PRIOR: nKeySym = VK_PAGEUP; break; - case WXK_NEXT : nKeySym = VK_PAGEDOWN; break; + case WXK_PAGEUP: nKeySym = VK_PAGEUP; break; + case WXK_PAGEDOWN: nKeySym = VK_PAGEDOWN; break; case WXK_END: nKeySym = VK_END; break; case WXK_HOME : nKeySym = VK_HOME; break; case WXK_LEFT : nKeySym = VK_LEFT; break; @@ -4644,7 +4416,8 @@ int wxCharCodeWXToOS2( int nId, case WXK_SCROLL: nKeySym = VK_SCRLLOCK; break; default: { - *bIsVirtual = false; + if ( bIsVirtual ) + *bIsVirtual = false; nKeySym = nId; break; } @@ -4652,6 +4425,29 @@ int wxCharCodeWXToOS2( int nId, return nKeySym; } // end of wxCharCodeWXToOS2 + +bool wxGetKeyState(wxKeyCode key) +{ + wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key != + WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons")); + + const LONG vk = wxCharCodeWXToOS2(key); + // if the requested key is a LED key, return true if the led is pressed + if ( key == WXK_NUMLOCK || key == WXK_CAPITAL || key == WXK_SCROLL ) + { + // low order bit means LED is highlighted and high order one means the + // key is down; for compatibility with the other ports return true if + // either one is set + return ::WinGetKeyState(HWND_DESKTOP, vk) != 0; + + } + else // normal key + { + return IsKeyDown(vk); + } +} + + wxWindow* wxGetActiveWindow() { HWND hWnd = ::WinQueryActiveWindow(HWND_DESKTOP); @@ -5168,14 +4964,14 @@ wxWindow* wxFindWindowAtPointer(wxPoint& WXUNUSED(rPt)) wxWindow* wxFindWindowAtPoint(const wxPoint& rPt) { - POINTL vPt2; + 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; + 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 @@ -5191,12 +4987,29 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& rPt) // Get the current mouse position. wxPoint wxGetMousePosition() { - POINTL vPt; + POINTL vPt; ::WinQueryPointerPos(HWND_DESKTOP, &vPt); return wxPoint(vPt.x, vPt.y); } +wxMouseState wxGetMouseState() +{ + wxMouseState ms; + wxPoint pt = wxGetMousePosition(); + ms.SetX(pt.x); + ms.SetY(pt.y); + ms.SetLeftDown(IsKeyDown(VK_BUTTON1)); + ms.SetMiddleDown(IsKeyDown(VK_BUTTON3)); + ms.SetRightDown(IsKeyDown(VK_BUTTON2)); + ms.SetControlDown(IsCtrlDown()); + ms.SetShiftDown(IsShiftDown()); + ms.SetAltDown(IsKeyDown(VK_ALT)|IsKeyDown(VK_ALTGRAF)); + ms.SetMetaDown(IsKeyDown(VK_ALTGRAF)); + return ms; +} + + wxWindowOS2* FindWindowForMouseEvent( wxWindow* pWin, short* WXUNUSED(pnX), short* WXUNUSED(pnY) )