]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
force making stats
[wxWidgets.git] / src / os2 / window.cpp
index 0e3bf3063f69eb2e6a1aa4d8b60f43dc62e3661e..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"
@@ -138,10 +139,14 @@ MRESULT EXPENTRY wxWndProc( HWND hWnd
     const char *wxGetMessageName(int message);
 #endif  //__WXDEBUG__
 
-void      wxRemoveHandleAssociation(wxWindowOS2* pWin);
-void      wxAssociateWinWithHandle( HWND         hWnd
-                                   ,wxWindowOS2* pWin
-                                  );
+wxWindowOS2* FindWindowForMouseEvent( wxWindow* pWin
+                                     ,short*    pnX
+                                     ,short*    pnY
+                                    );
+void         wxRemoveHandleAssociation(wxWindowOS2* pWin);
+void         wxAssociateWinWithHandle( HWND         hWnd
+                                      ,wxWindowOS2* pWin
+                                     );
 wxWindow* wxFindWinFromHandle(WXHWND hWnd);
 
 //
@@ -289,11 +294,10 @@ void wxWindowOS2::Init()
     //
     // PM specific
     //
-    m_bDoubleClickAllowed = 0;
     m_bWinCaptured = FALSE;
 
     m_isBeingDeleted        = FALSE;
-    m_fnOldWndProc          = 0;
+    m_fnOldWndProc          = NULL;
     m_bUseCtl3D             = FALSE;
     m_bMouseInWindow        = FALSE;
     m_bLastKeydownProcessed = FALSE;
@@ -338,12 +342,12 @@ wxWindowOS2::~wxWindowOS2()
 
     for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent())
     {
-        wxFrame*                    pFrame = wxDynamicCast(pWin, wxFrame);
+        wxTopLevelWindow*           pFrame = wxDynamicCast(pWin, wxTopLevelWindow);
 
         if (pFrame)
         {
             if (pFrame->GetLastFocus() == this)
-                pFrame->SetLastFocus((wxWindow*)NULL);
+                pFrame->SetLastFocus(NULL);
         }
     }
 
@@ -439,17 +443,15 @@ bool wxWindowOS2::Create(
     // Generic OS/2 Windows have no Control Data but other classes
     // that call OS2Create may have some.
     //
-    OS2Create( (PSZ)wxCanvasClassName
-              ,rName.c_str()
-              ,ulCreateFlags
-              ,rPos
-              ,rSize
-              ,NULL         // Control Data
-              ,dwExStyle
-              ,TRUE         // Child
-             );
-
-    return(TRUE);
+    return(OS2Create( (PSZ)wxCanvasClassName
+                     ,rName.c_str()
+                     ,ulCreateFlags
+                     ,rPos
+                     ,rSize
+                     ,NULL         // Control Data
+                     ,dwExStyle
+                     ,TRUE         // Child
+                    ));
 } // end of wxWindowOS2::Create
 
 // ---------------------------------------------------------------------------
@@ -465,6 +467,14 @@ void wxWindowOS2::SetFocus()
         ::WinSetFocus(HWND_DESKTOP, hWnd);
 } // end of wxWindowOS2::SetFocus
 
+void wxWindowOS2::SetFocusFromKbd()
+{
+    //
+    // Nothing else to do under OS/2
+    //
+    wxWindowBase::SetFocusFromKbd();
+} // end of wxWindowOS2::SetFocus
+
 wxWindow* wxWindowBase::FindFocus()
 {
     HWND                            hWnd = ::WinQueryFocus(HWND_DESKTOP);
@@ -1740,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)
     {
@@ -1811,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
@@ -2319,17 +2343,6 @@ bool wxWindowOS2::OS2ProcessMessage(
     pMsg = pMsg; // just shut up the compiler
 #endif // __WXUNIVERSAL__
 
-#if wxUSE_TOOLTIPS
-    if ( m_tooltip )
-    {
-        // relay mouse move events to the tooltip control
-        QMSG*                       pQMsg = (QMSG*)pMsg;
-
-        if (pQMsg->msg == WM_MOUSEMOVE )
-            m_tooltip->RelayEvent(pMsg);
-    }
-#endif // wxUSE_TOOLTIPS
-
     return FALSE;
 } // end of wxWindowOS2::OS2ProcessMessage
 
@@ -2581,6 +2594,8 @@ MRESULT wxWindowOS2::OS2WindowProc(
                     {
                         if (pFrame->GetStatusBar())
                             pFrame->PositionStatusBar();
+                        if (pFrame->GetToolBar())
+                            pFrame->PositionToolBar();
                     }
                 }
             }
@@ -2649,12 +2664,38 @@ MRESULT wxWindowOS2::OS2WindowProc(
         case WM_BUTTON3MOTIONEND:
         case WM_BUTTON3MOTIONSTART:
             {
-                short x = LOWORD(wParam);
-                short y = HIWORD(wParam);
+                if (uMsg == WM_BUTTON1DOWN && AcceptsFocus())
+                    SetFocus();
+
+                short               nX = LOWORD(wParam);
+                short               nY = HIWORD(wParam);
 
-                bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam);
+                //
+                // Redirect the event to a static control if necessary
+                //
+                if (this == GetCapture())
+                {
+                    bProcessed = HandleMouseEvent( uMsg
+                                                  ,nX
+                                                  ,nY
+                                                  ,(WXUINT)SHORT1FROMMP(wParam)
+                                                 );
+                }
+                else
+                {
+                    wxWindow*       pWin = FindWindowForMouseEvent( this
+                                                                   ,&nX
+                                                                   ,&nY
+                                                                  );
+                    bProcessed = pWin->HandleMouseEvent( uMsg
+                                                        ,nX
+                                                        ,nY
+                                                        ,(WXUINT)SHORT1FROMMP(wParam)
+                                                       );
+                }
             }
             break;
+
         case WM_SYSCOMMAND:
             bProcessed = HandleSysCommand(wParam, lParam);
             break;
@@ -2694,10 +2735,13 @@ MRESULT wxWindowOS2::OS2WindowProc(
             break;
 
         case WM_QUERYDLGCODE:
-            if ( m_lDlgCode )
+            if (!IsOfStandardClass())
             {
-                mResult = (MRESULT)m_lDlgCode;
-                bProcessed = TRUE;
+                if ( m_lDlgCode )
+                {
+                    mResult = (MRESULT)m_lDlgCode;
+                    bProcessed = TRUE;
+                }
             }
             //
             //else: get the dlg code from the DefWindowProc()
@@ -2837,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)
@@ -2884,7 +2933,7 @@ MRESULT wxWindowOS2::OS2WindowProc(
             if ( bProcessed )
             {
                 // we never set focus from here
-                mResult = FALSE;
+                mResult = (MRESULT)FALSE;
             }
             break;
 
@@ -3029,36 +3078,37 @@ bool wxWindowOS2::OS2GetCreateWindowCoords(
 ) const
 {
     bool                            bNonDefault = FALSE;
+    static const int                DEFAULT_Y = 200;
+    static const int                DEFAULT_H = 250;
 
     if (rPos.x == -1)
     {
-        //
-        // If set x to CW_USEDEFAULT, y parameter is ignored anyhow so we can
-        // just as well set it to CW_USEDEFAULT as well
         rnX = rnY = CW_USEDEFAULT;
     }
     else
     {
         rnX = rPos.x;
-        rnY = rPos.y == -1 ? CW_USEDEFAULT : rPos.y;
+        rnY = rPos.y == -1 ? DEFAULT_Y : rPos.y;
         bNonDefault = TRUE;
     }
     if (rSize.x == -1)
     {
-        //
-        // As abobe, h is not used at all in this case anyhow
-        //
         rnWidth = rnHeight = CW_USEDEFAULT;
     }
     else
     {
         rnWidth  = rSize.x;
-        rnHeight = rSize.y == -1 ? CW_USEDEFAULT : rSize.y;
+        rnHeight = rSize.y == -1 ? DEFAULT_H : rSize.y;
         bNonDefault = TRUE;
     }
     return bNonDefault;
 } // end of wxWindowOS2::OS2GetCreateWindowCoords
 
+WXHWND wxWindowOS2::OS2GetParent() const
+{
+    return m_parent ? m_parent->GetHWND() : NULL;
+}
+
 bool wxWindowOS2::OS2Create(
   PSZ                               zClass
 , const char*                       zTitle
@@ -3091,31 +3141,6 @@ bool wxWindowOS2::OS2Create(
                              ,nHeight
                             );
 
-    if (GetWindowStyleFlag() & wxPOPUP_WINDOW)
-        hParent = HWND_DESKTOP;
-    else
-    {
-        if ((bIsChild || HasFlag(wxFRAME_TOOL_WINDOW)) && pParent )
-        {
-            //
-            // This is either a normal child window or a top level window with
-            // wxFRAME_TOOL_WINDOW style (see below)
-            //
-            hParent = GetHwndOf(pParent);
-        }
-        else
-        {
-            //
-            // This is either a window for which no parent was specified (not
-            // much we can do then) or a frame without wxFRAME_TOOL_WINDOW
-            // style: we should use NULL parent HWND for it or it would be
-            // always on top of its parent which is not what we usually want
-            // (in fact, we only want it for frames with the special
-            // wxFRAME_TOOL_WINDOW as above)
-            //
-            hParent = NULL;
-        }
-    }
     if (bIsChild)
     {
         lControlId = GetId();
@@ -3133,20 +3158,20 @@ bool wxWindowOS2::OS2Create(
     {
         sClassName += wxT("NR");
     }
-    m_hWnd = (WXHWND)::WinCreateWindow( (HWND)hParent
-                                      ,(PSZ)sClassName.c_str()
-                                      ,(PSZ)zTitle ? zTitle : ""
-                                      ,(ULONG)dwStyle
-                                      ,(LONG)0L
-                                      ,(LONG)0L
-                                      ,(LONG)0L
-                                      ,(LONG)0L
-                                      ,NULLHANDLE
-                                      ,HWND_TOP
-                                      ,(ULONG)lControlId
-                                      ,pCtlData
-                                      ,NULL
-                                     );
+    m_hWnd = (WXHWND)::WinCreateWindow( (HWND)OS2GetParent()
+                                       ,(PSZ)sClassName.c_str()
+                                       ,(PSZ)zTitle ? zTitle : ""
+                                       ,(ULONG)dwStyle
+                                       ,(LONG)0L
+                                       ,(LONG)0L
+                                       ,(LONG)0L
+                                       ,(LONG)0L
+                                       ,NULLHANDLE
+                                       ,HWND_TOP
+                                       ,(ULONG)lControlId
+                                       ,pCtlData
+                                       ,NULL
+                                      );
     if (!m_hWnd)
     {
         vError = ::WinGetLastError(wxGetInstance());
@@ -3283,7 +3308,7 @@ bool wxWindowOS2::HandleSetFocus(
 } // end of wxWindowOS2::HandleSetFocus
 
 bool wxWindowOS2::HandleKillFocus(
-  WXHWND                            WXUNUSED(hWnd)
+  WXHWND                            hWnd
 )
 {
 #if wxUSE_CARET
@@ -3296,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
 
@@ -3908,6 +3960,7 @@ void wxWindowOS2::InitMouseEvent(
     rEvent.m_rightDown   = ((uFlags & VK_BUTTON2) != 0);
     rEvent.SetTimestamp(s_currentMsg.time);
     rEvent.m_eventObject = this;
+    rEvent.SetId(GetId());
 
 #if wxUSE_MOUSEEVENT_HACK
     m_lastMouseX = nX;
@@ -3923,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
@@ -3951,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
 
@@ -4058,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))
@@ -4079,7 +4148,7 @@ bool wxWindowOS2::HandleChar(
 
                 default:
                     bCtrlDown = TRUE;
-                    vId = vId + 'a' - 1;
+                    break;
             }
         }
     }
@@ -4347,7 +4416,19 @@ int wxWindowOS2::GetOS2ParentHeight(
             IsKindOf(CLASSINFO(wxMenuBar))   ||
             IsKindOf(CLASSINFO(wxToolBar))
            )
-            return(pParent->GetSize().y);
+        {
+            if (IsKindOf(CLASSINFO(wxToolBar)))
+            {
+                wxFrame*            pFrame = wxDynamicCast(GetParent(), wxFrame);
+
+                if (pFrame->GetToolBar() == this)
+                    return(pParent->GetSize().y);
+                else
+                    return(pParent->GetClientSize().y);
+            }
+            else
+                return(pParent->GetSize().y);
+        }
         else
             return(pParent->GetClientSize().y);
     }
@@ -5101,3 +5182,108 @@ wxPoint wxGetMousePosition()
     return wxPoint(vPt.x, vPt.y);
 }
 
+wxWindowOS2* FindWindowForMouseEvent(
+  wxWindow*                         pWin
+, short*                            pnX
+, short*                            pnY
+)
+{
+    HWND                            hWnd = GetHwndOf(pWin);
+    HWND                            hWndUnderMouse;
+    POINTL                          vPoint;
+    BOOL                            rcEnabled = FALSE;
+    BOOL                            rcVisible = FALSE;
+    HWND                            hWndDesktop = HWND_DESKTOP;
+
+    ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
+    hWndUnderMouse = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE);
+    if (hWndUnderMouse != HWND_DESKTOP)
+    {
+        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 &&
+         rcVisible && rcEnabled)
+    {
+        wxWindow*                       pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
+
+        if (pWinUnderMouse)
+        {
+            //
+            // Translate the mouse coords to the other window coords
+            //
+            pWin = pWinUnderMouse;
+        }
+    }
+    return pWin;
+} // end of FindWindowForMouseEvent
+