]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
force making stats
[wxWidgets.git] / src / os2 / window.cpp
index 38cc1963b1bc202eca259167594f13089f0da6af..85f6f74323cd8543018f932db2f5e0a418ffd86a 100644 (file)
@@ -35,6 +35,7 @@
     #include "wx/scrolwin.h"
     #include "wx/radiobox.h"
     #include "wx/slider.h"
+    #include "wx/statbox.h"
     #include "wx/statusbr.h"
     #include "wx/toolbar.h"
     #include "wx/settings.h"
@@ -442,19 +443,15 @@ bool wxWindowOS2::Create(
     // Generic OS/2 Windows have no Control Data but other classes
     // that call OS2Create may have some.
     //
-    bool                            bRetVal = OS2Create( (PSZ)wxCanvasClassName
-                                                        ,rName.c_str()
-                                                        ,ulCreateFlags
-                                                        ,rPos
-                                                        ,rSize
-                                                        ,NULL         // Control Data
-                                                        ,dwExStyle
-                                                        ,TRUE         // Child
-                                                       );
-
-    if (bRetVal)
-        ::WinSubclassWindow(m_hWnd, (PFNWP)wxWndProc);
-    return(bRetVal);
+    return(OS2Create( (PSZ)wxCanvasClassName
+                     ,rName.c_str()
+                     ,ulCreateFlags
+                     ,rPos
+                     ,rSize
+                     ,NULL         // Control Data
+                     ,dwExStyle
+                     ,TRUE         // Child
+                    ));
 } // end of wxWindowOS2::Create
 
 // ---------------------------------------------------------------------------
@@ -1753,19 +1750,6 @@ void wxWindowOS2::DoSetSize(
     int                             nY2 = nY;
     wxWindow*                       pParent = (wxWindow*)GetParent();
 
-    if (pParent && !IsKindOf(CLASSINFO(wxDialog)))
-    {
-        int                         nOS2Height = GetOS2ParentHeight(pParent);
-
-        nY2 = nOS2Height - (nY2 + nHeight);
-    }
-    else
-    {
-        RECTL                       vRect;
-
-        ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
-        nY2 = vRect.yTop - (nY2 + nHeight);
-    }
     if (nX == nCurrentX && nY2 == nCurrentY &&
         nWidth == nCurrentWidth && nHeight == nCurrentHeight)
     {
@@ -1824,34 +1808,61 @@ void wxWindowOS2::DoSetClientSize(
 , int                               nHeight
 )
 {
-    wxWindow*                       pParent = GetParent();
-    HWND                            hWnd = GetHwnd();
-    HWND                            hParentWnd = (HWND)0;
     POINTL                          vPoint;
-    RECTL                           vRect;
-    RECTL                           vRect2;
-    RECTL                           vRect3;
-    HWND                            hClientWnd = (HWND)0;
+    int                             nActualWidth;
+    int                             nActualHeight;
+    wxWindow*                       pParent = (wxWindow*)GetParent();
+    HWND                            hParentWnd = (HWND)0;
 
-    hClientWnd = ::WinWindowFromID(hWnd, FID_CLIENT);
-    ::WinQueryWindowRect(hClientWnd, &vRect2);
-    ::WinQueryWindowRect(hWnd, &vRect);
-    ::WinQueryWindowRect(hParentWnd, &vRect3);
+    if (pParent)
+        hParentWnd = (HWND)pParent->GetHWND();
 
-    int                             nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
-    int                             nActualHeight = vRect2.yTop - vRect2.yBottom - vRect.yTop + nHeight;
+    if (IsKindOf(CLASSINFO(wxFrame)))
+    {
+        wxFrame*                    pFrame = wxDynamicCast(this, wxFrame);
+        HWND                        hFrame = pFrame->GetFrame();
+        RECTL                       vRect;
+        RECTL                       vRect2;
+        RECTL                       vRect3;
 
-    vPoint.x = vRect2.xLeft;
-    vPoint.y = vRect2.yBottom;
-    if (pParent)
+        ::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
     {
-        vPoint.x -= vRect3.xLeft;
-        vPoint.y -= vRect3.yBottom;
+        int                         nX;
+        int                         nY;
+
+        GetPosition(&nX, &nY);
+        nActualWidth  = nWidth;
+        nActualHeight = nHeight;
+
+        vPoint.x = nX;
+        vPoint.y = nY;
     }
+    DoMoveWindow( vPoint.x
+                 ,vPoint.y
+                 ,nActualWidth
+                 ,nActualHeight
+                );
 
-    DoMoveWindow(vPoint.x, vPoint.y, nActualWidth, nActualHeight);
+    wxSizeEvent                     vEvent( wxSize( nWidth
+                                                   ,nHeight
+                                                  )
+                                           ,m_windowId
+                                          );
 
-    wxSizeEvent                     vEvent(wxSize(nWidth, nHeight), m_windowId);
     vEvent.SetEventObject(this);
     GetEventHandler()->ProcessEvent(vEvent);
 } // end of wxWindowOS2::DoSetClientSize
@@ -2870,6 +2881,11 @@ MRESULT wxWindowOS2::OS2WindowProc(
                         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)
@@ -2917,7 +2933,7 @@ MRESULT wxWindowOS2::OS2WindowProc(
             if ( bProcessed )
             {
                 // we never set focus from here
-                mResult = FALSE;
+                mResult = (MRESULT)FALSE;
             }
             break;
 
@@ -3292,7 +3308,7 @@ bool wxWindowOS2::HandleSetFocus(
 } // end of wxWindowOS2::HandleSetFocus
 
 bool wxWindowOS2::HandleKillFocus(
-  WXHWND                            WXUNUSED(hWnd)
+  WXHWND                            hWnd
 )
 {
 #if wxUSE_CARET
@@ -3305,11 +3321,38 @@ bool wxWindowOS2::HandleKillFocus(
     }
 #endif // wxUSE_CARET
 
+#if wxUSE_TEXTCTRL
+    // 
+    // If it's a wxTextCtrl don't send the event as it will be done
+    // after the control gets to process it.
+    //
+    wxTextCtrl*                     pCtrl = wxDynamicCastThis(wxTextCtrl);
+
+    if (pCtrl)
+    {
+        return FALSE;
+    }
+#endif
+
+    // 
+    // Don't send the event when in the process of being deleted.  This can
+    // only cause problems if the event handler tries to access the object.
+    //
+    if ( m_isBeingDeleted )
+    {
+        return FALSE;
+    }
+
     wxFocusEvent                    vEvent( wxEVT_KILL_FOCUS
                                            ,m_windowId
                                           );
 
     vEvent.SetEventObject(this);
+
+    // 
+    // wxFindWinFromHandle() may return NULL, it is ok
+    //
+    vEvent.SetWindow(wxFindWinFromHandle(hWnd));
     return GetEventHandler()->ProcessEvent(vEvent);
 } // end of wxWindowOS2::HandleKillFocus
 
@@ -3933,6 +3976,8 @@ bool wxWindowOS2::HandleMouseEvent(
 , WXUINT                            uFlags
 )
 {
+    bool                            bProcessed = FALSE;
+
     //
     // The mouse events take consecutive IDs from WM_MOUSEFIRST to
     // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
@@ -3961,6 +4006,18 @@ bool wxWindowOS2::HandleMouseEvent(
                    ,uFlags
                   );
 
+    bProcessed = GetEventHandler()->ProcessEvent(vEvent);
+    if (!bProcessed)
+    {
+        HPOINTER                    hPtr = ::WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE);
+        HPOINTER                    hCursor = (HPOINTER)GetCursor().GetHCURSOR();
+
+        if (hCursor != NULLHANDLE)
+        {
+            ::WinSetPointer(HWND_DESKTOP, hCursor);
+            bProcessed = TRUE;
+        }
+    }
     return GetEventHandler()->ProcessEvent(vEvent);
 } // end of wxWindowOS2::HandleMouseEvent
 
@@ -4068,7 +4125,9 @@ bool wxWindowOS2::HandleChar(
     if (isASCII)
     {
         //
-        // If 1 -> 26, translate to CTRL plus a letter.
+        // If 1 -> 26, translate to either special keycode or just set
+        // ctrlDown.  IOW, Ctrl-C should result in keycode == 3 and
+        // ControlDown() == TRUE.
         //
         vId = (int)wParam;
         if ((vId > 0) && (vId < 27))
@@ -4089,7 +4148,7 @@ bool wxWindowOS2::HandleChar(
 
                 default:
                     bCtrlDown = TRUE;
-                    vId = vId + 'a' - 1;
+                    break;
             }
         }
     }
@@ -5129,50 +5188,99 @@ wxWindowOS2* FindWindowForMouseEvent(
 , short*                            pnY
 )
 {
-    wxCHECK_MSG( pnX && pnY, pWin, _T("NULL pointer in FindWindowForMouseEvent") );
-    POINTL                          vPoint = { *pnX, *pnY };
     HWND                            hWnd = GetHwndOf(pWin);
     HWND                            hWndUnderMouse;
+    POINTL                          vPoint;
+    BOOL                            rcEnabled = FALSE;
+    BOOL                            rcVisible = FALSE;
+    HWND                            hWndDesktop = HWND_DESKTOP;
 
-    //
-    // First try to find a non transparent child: this allows us to send events
-    // to a static text which is inside a static box, for example
-    //
-
-    hWndUnderMouse = ::WinWindowFromPoint( hWnd
-                                          ,&vPoint
-                                          ,TRUE
-                                         );
-    if (!hWndUnderMouse || hWndUnderMouse == hWnd)
+    ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
+    hWndUnderMouse = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE);
+    if (hWndUnderMouse != HWND_DESKTOP)
     {
-        //
-        // Now try any child window at all
-        //
-        hWndUnderMouse = ::WinWindowFromPoint( HWND_DESKTOP
-                                              ,&vPoint
-                                              ,TRUE
-                                             );
+        wxWindow*                   pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
 
+        if (pWinUnderMouse)
+        {
+            wxWindowList::Node*     pCurrent = pWinUnderMouse->GetChildren().GetFirst();
+            wxWindow*               pChild = NULL;
+            wxWindow*               pGrandChild = NULL;
+            RECTL                   vRect;
+            POINTL                  vPoint2;
+
+            ::WinMapWindowPoints(HWND_DESKTOP, hWndUnderMouse, &vPoint, 1);
+            //
+            // Find a child window mouse might be under
+            //
+            while (pCurrent)
+            {
+                wxWindow*                   pChild = pCurrent->GetData();
+
+                vPoint2.x = vPoint.x;
+                vPoint2.y = vPoint.y;
+                ::WinMapWindowPoints(hWndUnderMouse, pChild->GetHWND(), &vPoint2, 1);
+                ::WinQueryWindowRect(pChild->GetHWND(), &vRect);
+                if (::WinPtInRect(vHabmain, &vRect, &vPoint2))
+                {
+                    if (pChild->IsTopLevel())
+                    {
+                        POINTL                  vPoint3;
+                        wxWindowList::Node*     pCurrent2 =pChild->GetChildren().GetFirst();
+
+                        while (pCurrent2)
+                        {
+                            wxWindow*           pGrandChild = pCurrent2->GetData();
+
+                            vPoint3.x = vPoint2.x;
+                            vPoint3.y = vPoint2.y;
+                            ::WinMapWindowPoints( pChild->GetHWND()
+                                                 ,pGrandChild->GetHWND()
+                                                 ,&vPoint3
+                                                 ,1
+                                                );
+                            ::WinQueryWindowRect(pGrandChild->GetHWND(), &vRect);
+                            if (::WinPtInRect(vHabmain, &vRect, &vPoint3))
+                            {
+                                hWndUnderMouse = GetHwndOf(pGrandChild);
+                                pWinUnderMouse = pGrandChild;
+                                break;
+                            }
+                            pCurrent2 = pCurrent2->GetNext();
+                        }
+                        if (pGrandChild)
+                            break;
+                    }
+                    hWndUnderMouse = GetHwndOf(pChild);
+                    pWinUnderMouse = pChild;
+                    rcVisible = ::WinIsWindowVisible(hWndUnderMouse);
+                    rcEnabled = ::WinIsWindowEnabled(hWndUnderMouse);
+                    if (rcVisible && rcEnabled)
+                        break;
+                }
+                pCurrent = pCurrent->GetNext();
+            }
+        }
     }
+    rcVisible = ::WinIsWindowVisible(hWndUnderMouse);
+    rcEnabled = ::WinIsWindowEnabled(hWndUnderMouse);
+
 
     //
     // Check that we have a child window which is susceptible to receive mouse
     // events: for this it must be shown and enabled
+    //
     if ( hWndUnderMouse &&
          hWndUnderMouse != hWnd &&
-         ::WinIsWindowVisible(hWndUnderMouse) &&
-         ::WinIsWindowEnabled(hWndUnderMouse))
+         rcVisible && rcEnabled)
     {
-        wxWindow*                   pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
+        wxWindow*                       pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
+
         if (pWinUnderMouse)
         {
-            // translate the mouse coords to the other window coords
-            pWin->ClientToScreen( (int*)pnX
-                                 ,(int*)pnY
-                                );
-            pWinUnderMouse->ScreenToClient( (int*)pnX
-                                           ,(int*)pnY
-                                          );
+            //
+            // Translate the mouse coords to the other window coords
+            //
             pWin = pWinUnderMouse;
         }
     }