]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
added wxGetMultiChoice() (which refuses to work for some reason - will fix
[wxWidgets.git] / src / os2 / window.cpp
index 01de71dd154368b5b4d6c8ac1026c3f675368fc4..7a31cfbbda2395e5d5fb447e0979700241c59efd 100644 (file)
     #include <stdio.h>
 #endif
 
+#define DEBUG_PRINTF(NAME)   { static int raz=0; \
+  printf( #NAME " %i\n",raz); fflush(stdout);       \
+   raz++;                                        \
+ }
+
 #if     wxUSE_OWNER_DRAWN
     #include "wx/ownerdrw.h"
 #endif
@@ -99,8 +104,8 @@ QMSG                      s_currentMsg;
 
 wxMenu*                   wxCurrentPopupMenu = NULL;
 extern wxList WXDLLEXPORT wxPendingDelete;
-#if defined(__VISAGECPP__) && (__IBMCPP__ < 400)
-extern wxChar*            wxCanvasClassName;
+#if !defined(__VISAGECPP__) || (__IBMCPP__ < 400)
+extern wxChar             wxCanvasClassName[];
 #endif
 wxList*                   wxWinHandleList = NULL;
 
@@ -244,6 +249,9 @@ bool wxWindow::OS2Command(
 , WXWORD                            WXUNUSED(uId)
 )
 {
+
+DEBUG_PRINTF(wxWindow::OS2Command);
+
     return(FALSE);
 }
 
@@ -293,6 +301,9 @@ void wxWindow::Init()
     m_lLastMouseY = -1;
     m_nLastMouseEvent = -1;
 #endif // wxUSE_MOUSEEVENT_HACK
+
+DEBUG_PRINTF(wxWindow::Init-End);
+
 } // wxWindow::Init
 
 //
@@ -300,14 +311,18 @@ void wxWindow::Init()
 //
 wxWindow::~wxWindow()
 {
+DEBUG_PRINTF(wxWindow::~wxWindow-Start);
     m_isBeingDeleted = TRUE;
 
     OS2DetachWindowMenu();
     if (m_parent)
         m_parent->RemoveChild(this);
     DestroyChildren();
+
     if (m_hWnd)
     {
+//      UnsubclassWin();
+
         if(!::WinDestroyWindow(GetHWND()))
             wxLogLastError(wxT("DestroyWindow"));
         //
@@ -315,6 +330,7 @@ wxWindow::~wxWindow()
         //
         wxRemoveHandleAssociation(this);
     }
+DEBUG_PRINTF(wxWindow::~wxWindow-End);
 } // end of wxWindow::~wxWindow
 
 bool wxWindow::Create(
@@ -382,6 +398,7 @@ bool wxWindow::Create(
               ,NULLHANDLE
               ,m_windowId
              );
+
     return(TRUE);
 } // end of wxWindow::Create
 
@@ -496,6 +513,7 @@ bool wxWindow::SetFont(
   const wxFont&                     rFont
 )
 {
+DEBUG_PRINTF(wxWindow::SetFont);
     if (!wxWindowBase::SetFont(rFont))
     {
         // nothing to do
@@ -714,28 +732,28 @@ void wxWindow::SubclassWin(
 
     wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") );
 
-    wxAssociateWinWithHandle(hwnd, this);
+//  wxAssociateWinWithHandle(hwnd, this);
 
     m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
-    ::WinSetWindowULong(hwnd, QWS_USER, (ULONG)wxWndProc);
+//    ::WinSetWindowULong(hwnd, QWL_USER, (ULONG)wxWndProc);
 } // end of wxWindow::SubclassWin
 
 void wxWindow::UnsubclassWin()
 {
-    wxRemoveHandleAssociation(this);
+//    wxRemoveHandleAssociation(this);
 
     //
     // Restore old Window proc
     //
-    HWND                            hwnd = GetHwnd();
+    HWND                            hwnd = GetHWND();
 
-    if (hwnd)
+    if (m_hWnd)
     {
-        m_hWnd = 0;
+//        m_hWnd = 0;
 
         wxCHECK_RET( ::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in UnsubclassWin") );
 
-        PFNWP                       fnProc = (PFNWP)::WinQueryWindowULong(hwnd, QWS_USER);
+        PFNWP                       fnProc = (PFNWP)::WinQueryWindowPtr(hwnd, QWP_PFNWP);
         if ( (m_fnOldWndProc != 0) && (fnProc != (PFNWP) m_fnOldWndProc))
         {
             WinSubclassWindow(hwnd, (PFNWP)m_fnOldWndProc);
@@ -1501,10 +1519,12 @@ MRESULT wxWindow::OS2DefWindowProc(
 , WXLPARAM                          lParam
 )
 {
+DEBUG_PRINTF(wxWindow::OS2DefWindowProc);
+
     if (m_fnOldWndProc)
-        return ((MRESULT)m_fnOldWndProc());
+        return (MRESULT)m_fnOldWndProc(GetHWND(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam);
     else
-        return (::WinDefWindowProc(GetHwnd(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam));
+        return ::WinDefWindowProc(GetHWND(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam);
 } // end of wxWindow::OS2DefWindowProc
 
 bool wxWindow::OS2ProcessMessage(
@@ -1513,6 +1533,8 @@ bool wxWindow::OS2ProcessMessage(
 {
     QMSG*                           pQMsg = (QMSG*)pMsg;
 
+DEBUG_PRINTF(OS2ProcessMessage);
+
     if (m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL))
     {
         //
@@ -1674,12 +1696,12 @@ bool wxWindow::OS2ProcessMessage(
                 }
             }
         }
+        //
+        // Let Dialogs process
+        //
+        if (::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0));
+            return TRUE;
     }
-    //
-    // Let Dialogs process
-    //
-    if (::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0));
-        return TRUE;
 
 #if wxUSE_TOOLTIPS
     if ( m_tooltip )
@@ -1699,7 +1721,11 @@ bool wxWindow::OS2TranslateMessage(
   WXMSG*                            pMsg
 )
 {
-    return m_acceleratorTable.Translate(this, pMsg);
+#if wxUSE_ACCEL
+  return m_acceleratorTable.Translate(m_hWnd, pMsg);
+#else
+  return FALSE;
+#endif //wxUSE_ACCEL
 } // end of wxWindow::OS2TranslateMessage
 
 // ---------------------------------------------------------------------------
@@ -1714,9 +1740,14 @@ void wxWindow::UnpackCommand(
 , WORD*                             pCmd
 )
 {
+/*
     *pId = LOWORD(wParam);
     *phWnd = (WXHWND)lParam;
     *pCmd = HIWORD(wParam);
+*/
+    *pId = LOWORD(wParam);
+    *phWnd = NULL;  // or may be GetHWND() ?
+    *pCmd = LOWORD(lParam);
 } // end of wxWindow::UnpackCommand
 
 void wxWindow::UnpackActivate(
@@ -1780,6 +1811,7 @@ MRESULT EXPENTRY wxWndProc(
     // Trace all ulMsgs - useful for the debugging
     //
 #ifdef __WXDEBUG__
+DEBUG_PRINTF(__WXDEBUG__wxWndProc);
     wxLogTrace(wxTraceMessages, wxT("Processing %s(wParam=%8lx, lParam=%8lx)"),
                wxGetMessageName(ulMsg), wParam, lParam);
 #endif // __WXDEBUG__
@@ -1798,7 +1830,8 @@ MRESULT EXPENTRY wxWndProc(
         pWnd->SetHWND((WXHWND)hWnd);
     }
 
-    MRESULT                         rc;
+    MRESULT                         rc = (MRESULT)0;
+
 
     //
     // Stop right here if we don't have a valid handle in our wxWindow object.
@@ -1816,6 +1849,7 @@ MRESULT EXPENTRY wxWndProc(
         else
             rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
     }
+
     return rc;
 } // end of wxWndProc
 
@@ -1833,22 +1867,26 @@ MRESULT wxWindow::OS2WindowProc(
     // Did we process the uMsg?
     //
     bool                            bProcessed = FALSE;
+    bool                            bAllow;
+    MRESULT                         mResult;
+    WXHICON                         hIcon;
+    WXHBRUSH                        hBrush;
 
     //
     // The return value
     //
-    union
-    {
-        bool                        bAllow;
-        MRESULT                     mResult;
-        WXHICON                     hIcon;
-        WXHBRUSH                    hBrush;
-    } vRc;
+//  union
+//  {
+//      bool                        bAllow;
+//      MRESULT                     mResult;
+//      WXHICON                     hIcon;
+//      WXHBRUSH                    hBrush;
+//  } vRc;
 
     //
     // For most messages we should return 0 when we do process the message
     //
-    vRc.mResult = (MRESULT)0;
+    mResult = (MRESULT)0;
 
     switch (uMsg)
     {
@@ -1864,14 +1902,15 @@ MRESULT wxWindow::OS2WindowProc(
                     //
                     // Return 0 to bAllow window creation
                     //
-                    vRc.mResult = (MRESULT)(bMayCreate ? 0 : -1);
+                    mResult = (MRESULT)(bMayCreate ? 0 : -1);
                 }
             }
             break;
 
         case WM_DESTROY:
-            bProcessed = HandleDestroy();
-            break;
+             HandleDestroy();
+             bProcessed = TRUE;
+             break;
 
         case WM_MOVE:
             bProcessed = HandleMove( LOWORD(lParam)
@@ -1900,6 +1939,7 @@ MRESULT wxWindow::OS2WindowProc(
                 bProcessed = HandleActivate( wState
                                             ,(WXHWND)hWnd
                                            );
+                bProcessed = FALSE;
             }
             break;
 
@@ -1911,6 +1951,7 @@ MRESULT wxWindow::OS2WindowProc(
             break;
 
         case WM_PAINT:
+DEBUG_PRINTF(WM_PAINT)
             bProcessed = HandlePaint();
             break;
 
@@ -1920,10 +1961,12 @@ MRESULT wxWindow::OS2WindowProc(
             // ourselves in ~wxWindow
             //
             bProcessed = TRUE;
-            vRc.mResult = (MRESULT)TRUE;
+            mResult = (MRESULT)TRUE;
+DEBUG_PRINTF(WM_CLOSE)
             break;
 
         case WM_SHOW:
+DEBUG_PRINTF(WM_SHOW)
             bProcessed = HandleShow(wParam != 0, (int)lParam);
             break;
 
@@ -1954,7 +1997,6 @@ MRESULT wxWindow::OS2WindowProc(
                 bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam);
             }
             break;
-
         case WM_SYSCOMMAND:
             bProcessed = HandleSysCommand(wParam, lParam);
             break;
@@ -1963,9 +2005,11 @@ MRESULT wxWindow::OS2WindowProc(
             {
                 WORD id, cmd;
                 WXHWND hwnd;
+DEBUG_PRINTF(WM_COMMAND-in)
                 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
 
                 bProcessed = HandleCommand(id, cmd, hwnd);
+DEBUG_PRINTF(WM_COMMAND-out)
             }
             break;
 
@@ -1988,14 +2032,14 @@ MRESULT wxWindow::OS2WindowProc(
                 }
 
                 if ( bProcessed )
-                    vRc.mResult = (MRESULT)TRUE;
+                    mResult = (MRESULT)TRUE;
             }
             break;
 
         case WM_QUERYDLGCODE:
             if ( m_lDlgCode )
             {
-                vRc.mResult = (MRESULT)m_lDlgCode;
+                mResult = (MRESULT)m_lDlgCode;
                 bProcessed = TRUE;
             }
             //
@@ -2094,7 +2138,7 @@ MRESULT wxWindow::OS2WindowProc(
 #if defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
         case WM_CTLCOLORCHANGE:
             {
-                bProcessed = HandleCtlColor(&vRc.hBrush);
+                bProcessed = HandleCtlColor(&hBrush);
             }
             break;
 #endif
@@ -2133,7 +2177,7 @@ MRESULT wxWindow::OS2WindowProc(
                 //
                 // We processed the message, i.e. erased the background
                 //
-                vRc.mResult = (MRESULT)TRUE;
+                mResult = (MRESULT)TRUE;
             }
             break;
 
@@ -2148,18 +2192,18 @@ MRESULT wxWindow::OS2WindowProc(
             if ( bProcessed )
             {
                 // we never set focus from here
-                vRc.mResult = FALSE;
+                mResult = FALSE;
             }
             break;
 
         // wxFrame specific message
         case WM_MINMAXFRAME:
-            bProcessed = HandleGetMinMaxInfo((PSWP)lParam);
+            bProcessed = HandleGetMinMaxInfo((PSWP)wParam);
             break;
 
         case WM_SYSVALUECHANGED:
             // TODO: do something
-            vRc.mResult = (MRESULT)TRUE;
+            mResult = (MRESULT)TRUE;
             break;
 
         //
@@ -2176,7 +2220,7 @@ MRESULT wxWindow::OS2WindowProc(
                 // processing this message - exactly what we need because we've
                 // just set the cursor.
                 //
-                vRc.mResult = (MRESULT)TRUE;
+                mResult = (MRESULT)TRUE;
             }
             break;
     }
@@ -2187,9 +2231,9 @@ MRESULT wxWindow::OS2WindowProc(
         wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
                    wxGetMessageName(uMsg));
 #endif // __WXDEBUG__
-        vRc.mResult = OS2DefWindowProc(uMsg, wParam, lParam);
+        mResult = OS2DefWindowProc(uMsg, wParam, lParam);
     }
-    return vRc.mResult;
+    return mResult;
 } // end of wxWindow::OS2WindowProc
 
 //
@@ -2326,10 +2370,10 @@ bool wxWindow::OS2Create(
 {
     ERRORID                         vError;
     wxString                        sError;
-    long                            lX1      = (long)CW_USEDEFAULT;
+    long                            lX1      = 0L;
     long                            lY1      = 0L;
-    long                            lWidth1  = (long)CW_USEDEFAULT;
-    long                            lHeight1 = 100L;
+    long                            lWidth1  = 20L;
+    long                            lHeight1 = 20L;
     int                             nControlId = 0;
 
     //
@@ -2357,6 +2401,7 @@ bool wxWindow::OS2Create(
         (ULONG)zClass == (ULONG)WC_COMBOBOX ||
         (ULONG)zClass == (ULONG)WC_CONTAINER ||
         (ULONG)zClass == (ULONG)WC_ENTRYFIELD ||
+        (ULONG)zClass == (ULONG)WC_FRAME ||
         (ULONG)zClass == (ULONG)WC_LISTBOX ||
         (ULONG)zClass == (ULONG)WC_MENU ||
         (ULONG)zClass == (ULONG)WC_NOTEBOOK ||
@@ -2394,6 +2439,7 @@ bool wxWindow::OS2Create(
         wxLogError("Can't create window of class %s!. Error: %s\n", zClass, sError);
         return FALSE;
     }
+    ::WinSetWindowULong(m_hWnd, QWL_USER, (ULONG) this);
     wxWndHook = NULL;
 
 #ifdef __WXDEBUG__
@@ -2413,6 +2459,12 @@ bool wxWindow::OS2Create(
     wxAssociateWinWithHandle((HWND)m_hWnd
                              ,this
                             );
+    //
+    // Now need to subclass window.
+    //
+
+    SubclassWin(GetHWND());
+
     return TRUE;
 } // end of wxWindow::OS2Create
 
@@ -2795,16 +2847,30 @@ void wxWindow::OnSysColourChanged(
 bool wxWindow::HandlePaint()
 {
     HRGN                            hRgn = NULLHANDLE;
+    wxPaintEvent                    vEvent;
+    HPS                             hPS;
+    RECTL                           vRect;
 
     if (::WinQueryUpdateRegion(GetHwnd(), hRgn) == RGN_NULL)
     {
          wxLogLastError("CreateRectRgn");
          return FALSE;
     }
-    m_updateRegion = wxRegion(hRgn);
+    //
+    // Debug code
+    //
+#ifdef __WXDEBUG__
+    {
+        HWND                        hWnd;
+        HWND                        hWnd0 = NULLHANDLE;
 
-    wxPaintEvent                    vEvent;
+        hWnd = GetHwnd();
+        if(hWnd != hWnd0)
+            printf("HandlePaint hWnd=%x  ",hWnd);
+    }
+#endif
 
+    m_updateRegion = wxRegion(hRgn);
     vEvent.SetEventObject(this);
     return (GetEventHandler()->ProcessEvent(vEvent));
 } // end of wxWindow::HandlePaint
@@ -3944,3 +4010,45 @@ static void TranslateKbdEventToMouse(
     pWin->ScreenToClient(pX, pY);
 } // end of TranslateKbdEventToMouse
 
+// Find the wxWindow at the current mouse position, returning the mouse
+// position.
+wxWindow* wxFindWindowAtPointer(
+  wxPoint&                          rPt
+)
+{
+    return wxFindWindowAtPoint(wxGetMousePosition());
+}
+
+wxWindow* wxFindWindowAtPoint(
+  const wxPoint&                    rPt
+)
+{
+    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;
+
+    //
+    // Try to find a window with a wxWindow associated with it
+    //
+    while (!pWin && (hWnd != 0))
+    {
+        hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
+        pWin = wxFindWinFromHandle((WXHWND)hWnd) ;
+    }
+    return pWin;
+}
+
+// Get the current mouse position.
+wxPoint wxGetMousePosition()
+{
+    POINTL                          vPt;
+
+    ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
+    return wxPoint(vPt.x, vPt.y);
+}
+