]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
adjusting to changed ownership (font is only created in the GetFont call of wxTextAttr)
[wxWidgets.git] / src / os2 / window.cpp
index 6af67866bbbd54f8cfac9df1ba08f9b5b67f7b9d..4a631a84520a848d5b4aa7094c52b4ec9edeb564 100644 (file)
     #include "wx/settings.h"
     #include "wx/intl.h"
     #include "wx/log.h"
     #include "wx/settings.h"
     #include "wx/intl.h"
     #include "wx/log.h"
+    #include "wx/textctrl.h"
+    #include "wx/menuitem.h"
     #include <stdio.h>
 #endif
 
     #include <stdio.h>
 #endif
 
+#include "wx/os2/dcclient.h"
+
 #if wxUSE_OWNER_DRAWN
     #include "wx/ownerdrw.h"
 #endif
 #if wxUSE_OWNER_DRAWN
     #include "wx/ownerdrw.h"
 #endif
@@ -57,8 +61,6 @@
     #include "wx/dnd.h"
 #endif
 
     #include "wx/dnd.h"
 #endif
 
-#include "wx/menuitem.h"
-
 #include "wx/os2/private.h"
 
 #if wxUSE_TOOLTIPS
 #include "wx/os2/private.h"
 
 #if wxUSE_TOOLTIPS
@@ -73,9 +75,6 @@
     #include "wx/caret.h"
 #endif // wxUSE_CARET
 
     #include "wx/caret.h"
 #endif // wxUSE_CARET
 
-
-#include "wx/textctrl.h"
-
 #include <string.h>
 
 //
 #include <string.h>
 
 //
 QMSG                      s_currentMsg;
 
 #if wxUSE_MENUS_NATIVE
 QMSG                      s_currentMsg;
 
 #if wxUSE_MENUS_NATIVE
-wxMenu*                   wxCurrentPopupMenu = NULL;
+extern wxMenu*            wxCurrentPopupMenu;
 #endif // wxUSE_MENUS_NATIVE
 
 // ---------------------------------------------------------------------------
 #endif // wxUSE_MENUS_NATIVE
 
 // ---------------------------------------------------------------------------
@@ -157,8 +156,9 @@ wxWindow* wxFindWinFromHandle(WXHWND hWnd);
 //
 // get the current state of SHIFT/CTRL keys
 //
 //
 // 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;
 
 
 static wxWindow*                    gpWinBeingCreated = NULL;
 
@@ -297,7 +297,6 @@ void wxWindowOS2::Init()
     m_bUseCtl3D             = false;
     m_bMouseInWindow        = false;
     m_bLastKeydownProcessed = false;
     m_bUseCtl3D             = false;
     m_bMouseInWindow        = false;
     m_bLastKeydownProcessed = false;
-    m_pChildrenDisabled     = NULL;
 
     //
     // wxWnd
 
     //
     // wxWnd
@@ -359,7 +358,6 @@ wxWindowOS2::~wxWindowOS2()
         //
         wxRemoveHandleAssociation(this);
     }
         //
         wxRemoveHandleAssociation(this);
     }
-    delete m_pChildrenDisabled;
 } // end of wxWindowOS2::~wxWindowOS2
 
 // real construction (Init() must have been called before!)
 } // end of wxWindowOS2::~wxWindowOS2
 
 // real construction (Init() must have been called before!)
@@ -481,70 +479,12 @@ wxWindow* wxWindowBase::DoFindFocus()
     return NULL;
 } // 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();
     HWND                            hWnd = GetHwnd();
-
     if ( hWnd )
         ::WinEnableWindow(hWnd, (BOOL)bEnable);
     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 )
 {
 
 bool wxWindowOS2::Show( bool bShow )
 {
@@ -574,7 +514,7 @@ void wxWindowOS2::Lower()
 
 void wxWindowOS2::SetLabel( const wxString& label )
 {
 
 void wxWindowOS2::SetLabel( const wxString& label )
 {
-    ::WinSetWindowText(GetHwnd(), (PSZ)label.c_str());
+    ::WinSetWindowText(GetHwnd(), label.c_str());
 } // end of wxWindowOS2::SetLabel
 
 wxString wxWindowOS2::GetLabel() const
 } // end of wxWindowOS2::SetLabel
 
 wxString wxWindowOS2::GetLabel() const
@@ -1144,7 +1084,7 @@ void wxWindowOS2::OnIdle(
                            ,vPoint.y
                            ,nState
                           );
                            ,vPoint.y
                            ,nState
                           );
-            (void)GetEventHandler()->ProcessEvent(rEvent);
+            (void)HandleWindowEvent(rEvent);
         }
     }
     if (wxUpdateUIEvent::CanUpdate(this))
         }
     }
     if (wxUpdateUIEvent::CanUpdate(this))
@@ -1171,12 +1111,12 @@ void wxWindowOS2::Update()
     ::WinUpdateWindow(GetHwnd());
 } // end of 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
 
 {
    ::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);
 
 {
    ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0);
 
@@ -1682,7 +1622,7 @@ void wxWindowOS2::DoSetClientSize( int nWidth,
     wxSize size( nWidth, nHeight );
     wxSizeEvent vEvent( size, m_windowId );
     vEvent.SetEventObject(this);
     wxSize size( nWidth, nHeight );
     wxSizeEvent vEvent( size, m_windowId );
     vEvent.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(vEvent);
+    HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::DoSetClientSize
 
 // ---------------------------------------------------------------------------
 } // end of wxWindowOS2::DoSetClientSize
 
 // ---------------------------------------------------------------------------
@@ -1735,7 +1675,6 @@ void wxWindowOS2::GetTextExtent( const wxString& rString,
     int         l;
     FONTMETRICS vFM; // metrics structure
     BOOL        bRc = FALSE;
     int         l;
     FONTMETRICS vFM; // metrics structure
     BOOL        bRc = FALSE;
-    char*       pStr;
     HPS         hPS;
 
     hPS = ::WinGetPS(GetHwnd());
     HPS         hPS;
 
     hPS = ::WinGetPS(GetHwnd());
@@ -1743,14 +1682,12 @@ void wxWindowOS2::GetTextExtent( const wxString& rString,
     l = rString.length();
     if (l > 0L)
     {
     l = rString.length();
     if (l > 0L)
     {
-        pStr = (PCH)rString.c_str();
-
         //
         // In world coordinates.
         //
         bRc = ::GpiQueryTextBox( hPS,
                                  l,
         //
         // In world coordinates.
         //
         bRc = ::GpiQueryTextBox( hPS,
                                  l,
-                                 pStr,
+                                 (char*) rString.wx_str(),
                                  TXTBOX_COUNT,// return maximum information
                                  avPoint      // array of coordinates points
                                 );
                                  TXTBOX_COUNT,// return maximum information
                                  avPoint      // array of coordinates points
                                 );
@@ -1849,10 +1786,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY )
     bool bIsWaiting = true;
     int nHeight;
 
     bool bIsWaiting = true;
     int nHeight;
 
-    // Protect against recursion
-    if (wxCurrentPopupMenu)
-        return false;
-
     pMenu->SetInvokingWindow(this);
     pMenu->UpdateUI();
 
     pMenu->SetInvokingWindow(this);
     pMenu->UpdateUI();
 
@@ -1869,7 +1802,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY )
         DoGetSize(0,&nHeight);
         nY = nHeight - nY;
     }
         DoGetSize(0,&nHeight);
         nY = nHeight - nY;
     }
-    wxCurrentPopupMenu = pMenu;
 
     ::WinPopupMenu( hWndParent
                    ,hWndOwner
 
     ::WinPopupMenu( hWndParent
                    ,hWndOwner
@@ -1890,7 +1822,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY )
         ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
     }
 
         ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
     }
 
-    wxCurrentPopupMenu = NULL;
     pMenu->SetInvokingWindow(NULL);
     return true;
 } // end of wxWindowOS2::DoPopupMenu
     pMenu->SetInvokingWindow(NULL);
     return true;
 } // end of wxWindowOS2::DoPopupMenu
@@ -2023,9 +1954,13 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg )
                         }
                         else
                         {
                         }
                         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())
                             {
 
                             if (pBtn && pBtn->IsEnabled())
                             {
@@ -2062,7 +1997,7 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg )
                 vEvent.SetWindowChange(bWindowChange);
                 vEvent.SetEventObject(this);
 
                 vEvent.SetWindowChange(bWindowChange);
                 vEvent.SetEventObject(this);
 
-                if (GetEventHandler()->ProcessEvent(vEvent))
+                if (HandleWindowEvent(vEvent))
                 {
                     wxButton*       pBtn = wxDynamicCast(FindFocus(), wxButton);
 
                 {
                     wxButton*       pBtn = wxDynamicCast(FindFocus(), wxButton);
 
@@ -2394,9 +2329,6 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg,
         case WM_BUTTON3MOTIONEND:
         case WM_BUTTON3MOTIONSTART:
             {
         case WM_BUTTON3MOTIONEND:
         case WM_BUTTON3MOTIONSTART:
             {
-                if (uMsg == WM_BUTTON1DOWN && AcceptsFocus())
-                    SetFocus();
-
                 short               nX = LOWORD(wParam);
                 short               nY = HIWORD(wParam);
 
                 short               nX = LOWORD(wParam);
                 short               nY = HIWORD(wParam);
 
@@ -2419,7 +2351,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg,
                                                                   );
                     if (!pWin->IsOfStandardClass())
                     {
                                                                   );
                     if (!pWin->IsOfStandardClass())
                     {
-                        if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() )
+                        if (uMsg == WM_BUTTON1DOWN && pWin->CanAcceptFocus() )
                             pWin->SetFocus();
                     }
                     bProcessed = pWin->HandleMouseEvent( uMsg
                             pWin->SetFocus();
                     }
                     bProcessed = pWin->HandleMouseEvent( uMsg
@@ -2642,6 +2574,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg,
                     }
                     break;
 
                     }
                     break;
 
+                case CBN_LBSELECT:
                 case BN_CLICKED: // Dups as LN_SELECT and CBN_LBSELECT
                     {
                         HWND                hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
                 case BN_CLICKED: // Dups as LN_SELECT and CBN_LBSELECT
                     {
                         HWND                hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
@@ -2698,11 +2631,19 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg,
                                                   ,(WXWORD)SHORT1FROMMP(wParam)
                                                  );
                         }
                                                   ,(WXWORD)SHORT1FROMMP(wParam)
                                                  );
                         }
+                        if (pWin->IsKindOf(CLASSINFO(wxChoice)))
+                        {
+                            wxChoice*           pChoice = wxDynamicCast(pWin, wxChoice);
+
+                            pChoice->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
+                                                ,(WXWORD)SHORT1FROMMP(wParam)
+                                               );
+                        }
                         return 0;
                     }
                     // break;
 
                         return 0;
                     }
                     // break;
 
-                case LN_ENTER:   /* dups as CBN_EFCHANGE */
+                case LN_ENTER:
                     {
                         HWND                hWnd = HWNDFROMMP(lParam);
                         wxWindowOS2*        pWin = wxFindWinFromHandle(hWnd);
                     {
                         HWND                hWnd = HWNDFROMMP(lParam);
                         wxWindowOS2*        pWin = wxFindWinFromHandle(hWnd);
@@ -2996,6 +2937,7 @@ bool wxWindowOS2::OS2Create( PSZ            zClass,
     long                 lControlId = 0L;
     wxWindowCreationHook vHook(this);
     wxString             sClassName((wxChar*)zClass);
     long                 lControlId = 0L;
     wxWindowCreationHook vHook(this);
     wxString             sClassName((wxChar*)zClass);
+    wxString             sTitle(zTitle ? zTitle : wxEmptyString);
 
     OS2GetCreateWindowCoords( rPos
                              ,rSize
 
     OS2GetCreateWindowCoords( rPos
                              ,rSize
@@ -3023,8 +2965,8 @@ bool wxWindowOS2::OS2Create( PSZ            zClass,
         sClassName += wxT("NR");
     }
     m_hWnd = (WXHWND)::WinCreateWindow( (HWND)OS2GetParent()
         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
                                        ,(ULONG)dwStyle
                                        ,(LONG)0L
                                        ,(LONG)0L
@@ -3081,7 +3023,7 @@ bool wxWindowOS2::HandleCreate( WXLPCREATESTRUCT WXUNUSED(vCs),
 {
     wxWindowCreateEvent             vEvent((wxWindow*)this);
 
 {
     wxWindowCreateEvent             vEvent((wxWindow*)this);
 
-    (void)GetEventHandler()->ProcessEvent(vEvent);
+    (void)HandleWindowEvent(vEvent);
     *pbMayCreate = true;
     return true;
 } // end of wxWindowOS2::HandleCreate
     *pbMayCreate = true;
     return true;
 } // end of wxWindowOS2::HandleCreate
@@ -3090,7 +3032,7 @@ bool wxWindowOS2::HandleDestroy()
 {
     wxWindowDestroyEvent            vEvent((wxWindow*)this);
     vEvent.SetId(GetId());
 {
     wxWindowDestroyEvent            vEvent((wxWindow*)this);
     vEvent.SetId(GetId());
-    (void)GetEventHandler()->ProcessEvent(vEvent);
+    (void)HandleWindowEvent(vEvent);
 
     //
     // Delete our drop target if we've got one
 
     //
     // Delete our drop target if we've got one
@@ -3129,7 +3071,7 @@ bool wxWindowOS2::HandleActivate(
                                            ,m_windowId
                                           );
     vEvent.SetEventObject(this);
                                            ,m_windowId
                                           );
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleActivate
 
 bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) )
 } // end of wxWindowOS2::HandleActivate
 
 bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) )
@@ -3139,7 +3081,7 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) )
     // purposes that we got it
     //
     wxChildFocusEvent               vEventFocus((wxWindow *)this);
     // purposes that we got it
     //
     wxChildFocusEvent               vEventFocus((wxWindow *)this);
-    (void)GetEventHandler()->ProcessEvent(vEventFocus);
+    (void)HandleWindowEvent(vEventFocus);
 
 #if wxUSE_CARET
     //
 
 #if wxUSE_CARET
     //
@@ -3163,7 +3105,7 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) )
     wxFocusEvent                    vEvent(wxEVT_SET_FOCUS, m_windowId);
 
     vEvent.SetEventObject(this);
     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 )
 } // end of wxWindowOS2::HandleSetFocus
 
 bool wxWindowOS2::HandleKillFocus( WXHWND hWnd )
@@ -3210,7 +3152,7 @@ bool wxWindowOS2::HandleKillFocus( WXHWND hWnd )
     // wxFindWinFromHandle() may return NULL, it is ok
     //
     vEvent.SetWindow(wxFindWinFromHandle(hWnd));
     // wxFindWinFromHandle() may return NULL, it is ok
     //
     vEvent.SetWindow(wxFindWinFromHandle(hWnd));
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleKillFocus
 
 // ---------------------------------------------------------------------------
 } // end of wxWindowOS2::HandleKillFocus
 
 // ---------------------------------------------------------------------------
@@ -3225,7 +3167,7 @@ bool wxWindowOS2::HandleShow(
     wxShowEvent                     vEvent(GetId(), bShow);
 
     vEvent.SetEventObject(this);
     wxShowEvent                     vEvent(GetId(), bShow);
 
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleShow
 
 bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) )
 } // end of wxWindowOS2::HandleShow
 
 bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) )
@@ -3233,7 +3175,7 @@ bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) )
     wxInitDialogEvent               vEvent(GetId());
 
     vEvent.SetEventObject(this);
     wxInitDialogEvent               vEvent(GetId());
 
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleInitDialog
 
 bool wxWindowOS2::HandleEndDrag(WXWPARAM WXUNUSED(wParam))
 } // end of wxWindowOS2::HandleInitDialog
 
 bool wxWindowOS2::HandleEndDrag(WXWPARAM WXUNUSED(wParam))
@@ -3260,7 +3202,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId,
                                  WXDRAWITEMSTRUCT* pItemStruct )
 {
 #if wxUSE_OWNER_DRAWN
                                  WXDRAWITEMSTRUCT* pItemStruct )
 {
 #if wxUSE_OWNER_DRAWN
-    wxDC                            vDc;
+    wxClientDC                      vDc(this);
 
 #if wxUSE_MENUS_NATIVE
     //
 
 #if wxUSE_MENUS_NATIVE
     //
@@ -3279,8 +3221,10 @@ bool wxWindowOS2::OS2OnDrawItem( int vId,
                                           ,pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft
                                           ,pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom
                                          );
                                           ,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
         //
         //
         // Load the wxWidgets Pallete and set to RGB mode
         //
@@ -3470,7 +3414,7 @@ bool wxWindowOS2::HandleSysColorChange()
     wxSysColourChangedEvent         vEvent;
 
     vEvent.SetEventObject(this);
     wxSysColourChangedEvent         vEvent;
 
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleSysColorChange
 
 bool wxWindowOS2::HandleCtlColor( WXHBRUSH* WXUNUSED(phBrush) )
 } // end of wxWindowOS2::HandleSysColorChange
 
 bool wxWindowOS2::HandleCtlColor( WXHBRUSH* WXUNUSED(phBrush) )
@@ -3503,7 +3447,7 @@ bool wxWindowOS2::HandlePaletteChanged()
     vEvent.SetEventObject(this);
     vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
 
     vEvent.SetEventObject(this);
     vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
 
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandlePaletteChanged
 
 //
 } // end of wxWindowOS2::HandlePaletteChanged
 
 //
@@ -3527,7 +3471,7 @@ void wxWindowOS2::OnSysColourChanged(
             wxSysColourChangedEvent vEvent;
 
             rEvent.SetEventObject(pWin);
             wxSysColourChangedEvent vEvent;
 
             rEvent.SetEventObject(pWin);
-            pWin->GetEventHandler()->ProcessEvent(vEvent);
+            pWin->HandleWindowEvent(vEvent);
         }
         node = node->GetNext();
     }
         }
         node = node->GetNext();
     }
@@ -3541,7 +3485,7 @@ void wxWindow::OnPaint (
   wxPaintEvent&                     rEvent
 )
 {
   wxPaintEvent&                     rEvent
 )
 {
-    HDC                             hDC = (HDC)wxPaintDC::FindDCInCache((wxWindow*) rEvent.GetEventObject());
+    HDC                             hDC = (HDC)wxPaintDCImpl::FindDCInCache((wxWindow*) rEvent.GetEventObject());
 
     if (hDC != 0)
     {
 
     if (hDC != 0)
     {
@@ -3569,15 +3513,10 @@ bool wxWindowOS2::HandlePaint()
          wxLogLastError(wxT("CreateRectRgn"));
          return false;
     }
          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.
     //
     // 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;
     RGNRECT                     vRgnData;
     PRECTL                      pUpdateRects = NULL;
     vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT;
@@ -3607,18 +3546,17 @@ bool wxWindowOS2::HandlePaint()
             {
                 int                 rectHeight;
                 rectHeight = pUpdateRects[i].yTop - pUpdateRects[i].yBottom;
             {
                 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;
         }
     }
             }
             ::GpiSetRegion(hPS, hRgn, vRgnData.crc, pUpdateRects);
             delete [] pUpdateRects;
         }
     }
-
     m_updateRegion = wxRegion(hRgn, hPS);
 
     vEvent.SetEventObject(this);
     m_updateRegion = wxRegion(hRgn, hPS);
 
     vEvent.SetEventObject(this);
-    bProcessed = GetEventHandler()->ProcessEvent(vEvent);
+    bProcessed = HandleWindowEvent(vEvent);
 
     if (!bProcessed &&
          IsKindOf(CLASSINFO(wxPanel)) &&
 
     if (!bProcessed &&
          IsKindOf(CLASSINFO(wxPanel)) &&
@@ -3732,25 +3670,26 @@ bool wxWindowOS2::HandleEraseBkgnd( WXHDC hDC )
     if (vSwp.fl & SWP_MINIMIZE)
         return true;
 
     if (vSwp.fl & SWP_MINIMIZE)
         return true;
 
-    wxDC vDC;
-
-    vDC.m_hPS = (HPS)hDC; // this is really a PS
-    vDC.SetWindow((wxWindow*)this);
+    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);
 
 
     wxEraseEvent vEvent(m_windowId, &vDC);
 
     vEvent.SetEventObject(this);
 
-    rc = GetEventHandler()->ProcessEvent(vEvent);
+    rc = HandleWindowEvent(vEvent);
 
 
-    vDC.m_hPS = NULLHANDLE;
+    impl->SetHPS(NULLHANDLE);
     return true;
 } // end of wxWindowOS2::HandleEraseBkgnd
 
 void wxWindowOS2::OnEraseBackground(wxEraseEvent& rEvent)
 {
     RECTL   vRect;
     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();
 
     APIRET  rc;
     LONG    lColor = m_backgroundColour.GetPixel();
 
@@ -3767,7 +3706,7 @@ bool wxWindowOS2::HandleMinimize()
     wxIconizeEvent                  vEvent(m_windowId);
 
     vEvent.SetEventObject(this);
     wxIconizeEvent                  vEvent(m_windowId);
 
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleMinimize
 
 bool wxWindowOS2::HandleMaximize()
 } // end of wxWindowOS2::HandleMinimize
 
 bool wxWindowOS2::HandleMaximize()
@@ -3775,7 +3714,7 @@ bool wxWindowOS2::HandleMaximize()
     wxMaximizeEvent                 vEvent(m_windowId);
 
     vEvent.SetEventObject(this);
     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 )
 } // end of wxWindowOS2::HandleMaximize
 
 bool wxWindowOS2::HandleMove( int nX, int nY )
@@ -3784,7 +3723,7 @@ bool wxWindowOS2::HandleMove( int nX, int nY )
     wxMoveEvent vEvent(pt, m_windowId);
 
     vEvent.SetEventObject(this);
     wxMoveEvent vEvent(pt, m_windowId);
 
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 }  // end of wxWindowOS2::HandleMove
 
 bool wxWindowOS2::HandleSize( int    nWidth,
 }  // end of wxWindowOS2::HandleMove
 
 bool wxWindowOS2::HandleSize( int    nWidth,
@@ -3795,7 +3734,7 @@ bool wxWindowOS2::HandleSize( int    nWidth,
     wxSizeEvent vEvent(sz, m_windowId);
 
     vEvent.SetEventObject(this);
     wxSizeEvent vEvent(sz, m_windowId);
 
     vEvent.SetEventObject(this);
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::HandleSize
 
 bool wxWindowOS2::HandleGetMinMaxInfo( PSWP pSwp )
 } // end of wxWindowOS2::HandleSize
 
 bool wxWindowOS2::HandleGetMinMaxInfo( PSWP pSwp )
@@ -3888,12 +3827,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_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());
     rEvent.SetTimestamp(s_currentMsg.time);
     rEvent.SetEventObject(this);
     rEvent.SetId(GetId());
@@ -3943,7 +3879,7 @@ bool wxWindowOS2::HandleMouseEvent( WXUINT uMsg,
                        ,uFlags
                        );
 
                        ,uFlags
                        );
 
-        bProcessed = GetEventHandler()->ProcessEvent(vEvent);
+        bProcessed = HandleWindowEvent(vEvent);
         if (!bProcessed)
         {
             HPOINTER hCursor = (HPOINTER)GetCursor().GetHCURSOR();
         if (!bProcessed)
         {
             HPOINTER hCursor = (HPOINTER)GetCursor().GetHCURSOR();
@@ -3977,7 +3913,7 @@ bool wxWindowOS2::HandleMouseMove( int nX,
                        ,uFlags
                       );
 
                        ,uFlags
                       );
 
-        (void)GetEventHandler()->ProcessEvent(vEvent);
+        (void)HandleWindowEvent(vEvent);
     }
     return HandleMouseEvent( WM_MOUSEMOVE
                             ,nX
     }
     return HandleMouseEvent( WM_MOUSEMOVE
                             ,nX
@@ -4099,7 +4035,7 @@ bool wxWindowOS2::HandleChar( WXWPARAM WXUNUSED(wParam),
         vEvent.m_controlDown = true;
     }
 
         vEvent.m_controlDown = true;
     }
 
-    return (GetEventHandler()->ProcessEvent(vEvent));
+    return (HandleWindowEvent(vEvent));
 }
 
 bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam,
 }
 
 bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam,
@@ -4123,7 +4059,7 @@ bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam,
                                           ,(MPARAM)wParam
                                          ));
 
                                           ,(MPARAM)wParam
                                          ));
 
-        if (GetEventHandler()->ProcessEvent(vEvent))
+        if (HandleWindowEvent(vEvent))
         {
             return true;
         }
         {
             return true;
         }
@@ -4152,7 +4088,7 @@ bool wxWindowOS2::HandleKeyUp( WXWPARAM wParam,
                                          ,(MPARAM)wParam
                                         ));
 
                                          ,(MPARAM)wParam
                                         ));
 
-        if (GetEventHandler()->ProcessEvent(vEvent))
+        if (HandleWindowEvent(vEvent))
             return true;
     }
     return false;
             return true;
     }
     return false;
@@ -4218,7 +4154,7 @@ bool wxWindowOS2::OS2OnScroll( int nOrientation,
         default:
             return false;
     }
         default:
             return false;
     }
-    return GetEventHandler()->ProcessEvent(vEvent);
+    return HandleWindowEvent(vEvent);
 } // end of wxWindowOS2::OS2OnScroll
 
 //
 } // end of wxWindowOS2::OS2OnScroll
 
 //
@@ -4441,7 +4377,8 @@ int wxCharCodeWXToOS2( int nId,
 {
     int nKeySym = 0;
 
 {
     int nKeySym = 0;
 
-    *bIsVirtual = true;
+    if ( bIsVirtual )
+        *bIsVirtual = true;
     switch (nId)
     {
         case WXK_CLEAR:     nKeySym = VK_CLEAR; break;
     switch (nId)
     {
         case WXK_CLEAR:     nKeySym = VK_CLEAR; break;
@@ -4487,7 +4424,8 @@ int wxCharCodeWXToOS2( int nId,
         case WXK_SCROLL:    nKeySym = VK_SCRLLOCK; break;
         default:
         {
         case WXK_SCROLL:    nKeySym = VK_SCRLLOCK; break;
         default:
         {
-            *bIsVirtual = false;
+            if ( bIsVirtual )
+                *bIsVirtual = false;
             nKeySym = nId;
             break;
         }
             nKeySym = nId;
             break;
         }
@@ -4501,9 +4439,20 @@ bool wxGetKeyState(wxKeyCode key)
     wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=
         WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));
 
     wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=
         WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));
 
-    // TODO
+    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;
 
 
-    return false;
+    }
+    else // normal key
+    {
+        return IsKeyDown(vk);
+    }
 }
 
 
 }
 
 
@@ -5046,12 +4995,29 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& rPt)
 // Get the current mouse position.
 wxPoint wxGetMousePosition()
 {
 // Get the current mouse position.
 wxPoint wxGetMousePosition()
 {
-    POINTL                          vPt;
+    POINTL vPt;
 
     ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
     return wxPoint(vPt.x, vPt.y);
 }
 
 
     ::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) )
 wxWindowOS2* FindWindowForMouseEvent( wxWindow* pWin,
                                       short*    WXUNUSED(pnX),
                                       short*    WXUNUSED(pnY) )