]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
corrected path splitting for mac relative paths
[wxWidgets.git] / src / os2 / window.cpp
index 9ffc8921ef4598b2a5d33712a1f6e4ac1e0cfb59..c30bdb8ba473a66866005eda2ff68c537520797c 100644 (file)
     #include "wx/button.h"
     #include "wx/msgdlg.h"
     #include "wx/scrolwin.h"
     #include "wx/button.h"
     #include "wx/msgdlg.h"
     #include "wx/scrolwin.h"
-
+    #include "wx/radiobox.h"
+    #include "wx/slider.h"
+    #include "wx/statusbr.h"
+    #include "wx/toolbar.h"
+    #include "wx/settings.h"
     #include <stdio.h>
 #endif
 
     #include <stdio.h>
 #endif
 
@@ -102,9 +106,6 @@ QMSG                      s_currentMsg;
 wxMenu*                   wxCurrentPopupMenu = NULL;
 #endif // wxUSE_MENUS_NATIVE
 
 wxMenu*                   wxCurrentPopupMenu = NULL;
 #endif // wxUSE_MENUS_NATIVE
 
-#if !defined(__VISAGECPP__) || (__IBMCPP__ < 400)
-extern wxChar             wxCanvasClassName[];
-#endif
 wxList*                   wxWinHandleList = NULL;
 
 // ---------------------------------------------------------------------------
 wxList*                   wxWinHandleList = NULL;
 
 // ---------------------------------------------------------------------------
@@ -330,7 +331,6 @@ wxWindowOS2::~wxWindowOS2()
 {
     m_isBeingDeleted = TRUE;
 
 {
     m_isBeingDeleted = TRUE;
 
-    OS2DetachWindowMenu();
     for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent())
     {
         wxFrame*                    pFrame = wxDynamicCast(pWin, wxFrame);
     for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent())
     {
         wxFrame*                    pFrame = wxDynamicCast(pWin, wxFrame);
@@ -545,7 +545,7 @@ wxString wxWindowOS2::GetTitle() const
     return wxGetWindowText(GetHWND());
 } // end of wxWindowOS2::GetTitle
 
     return wxGetWindowText(GetHWND());
 } // end of wxWindowOS2::GetTitle
 
-void wxWindowOS2::CaptureMouse()
+void wxWindowOS2::DoCaptureMouse()
 {
     HWND                            hWnd = GetHwnd();
 
 {
     HWND                            hWnd = GetHwnd();
 
@@ -556,7 +556,7 @@ void wxWindowOS2::CaptureMouse()
     }
 } // end of wxWindowOS2::GetTitle
 
     }
 } // end of wxWindowOS2::GetTitle
 
-void wxWindowOS2::ReleaseMouse()
+void wxWindowOS2::DoReleaseMouse()
 {
     if (m_bWinCaptured)
     {
 {
     if (m_bWinCaptured)
     {
@@ -583,77 +583,11 @@ bool wxWindowOS2::SetFont(
 
     HWND                            hWnd = GetHwnd();
 
 
     HWND                            hWnd = GetHwnd();
 
-    if (hWnd != 0)
-    {
-        char                        zFont[128];
-        char                        zFacename[30];
-        char                        zWeight[30];
-        char                        zStyle[30];
-
-        //
-        // The fonts available for Presentation Params are just three
-        // outline fonts, the rest are available to the GPI, so we must
-        // map the families to one of these three
-        //
-        switch(rFont.GetFamily())
-        {
-            case wxSCRIPT:
-            case wxDECORATIVE:
-            case wxROMAN:
-                strcpy(zFacename,"Times New Roman");
-                break;
-
-            case wxTELETYPE:
-            case wxMODERN:
-                strcpy(zFacename, "Courier");
-                break;
-
-            case wxSWISS:
-            case wxDEFAULT:
-            default:
-                strcpy(zFacename, "Helvetica");
-                break;
-        }
-
-        switch(rFont.GetWeight())
-        {
-            default:
-            case wxNORMAL:
-            case wxLIGHT:
-                zWeight[0] = '\0';
-                break;
-
-            case wxBOLD:
-            case wxFONTWEIGHT_MAX:
-                strcpy(zWeight, "Bold");
-                break;
-        }
-        switch(rFont.GetStyle())
-        {
-            case wxITALIC:
-            case wxSLANT:
-                strcpy(zStyle, "Italic");
-                break;
-
-            default:
-                zStyle[0] = '\0';
-                break;
-        }
-        sprintf(zFont, "%d.%s", rFont.GetPointSize(), zFacename);
-        if (zWeight[0] != '\0')
-        {
-            strcat(zFont, " ");
-            strcat(zFont, zWeight);
-        }
-        if (zStyle[0] != '\0')
-        {
-            strcat(zFont, " ");
-            strcat(zFont, zStyle);
-        }
-        ::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont) + 1, (PVOID)zFont);
-    }
+    wxOS2SetFont( hWnd
+                 ,rFont
+                );
     return(TRUE);
     return(TRUE);
-}
+} // end of wxWindowOS2::SetFont
 
 bool wxWindowOS2::SetCursor(
   const wxCursor&                   rCursor
 
 bool wxWindowOS2::SetCursor(
   const wxCursor&                   rCursor
@@ -1051,9 +985,20 @@ void wxWindowOS2::SubclassWin(
 {
     HWND                            hwnd = (HWND)hWnd;
 
 {
     HWND                            hwnd = (HWND)hWnd;
 
-    wxASSERT_MSG( !m_fnOldWndProc, wxT("subclassing window twice?") );
     wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") );
     wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") );
-    m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
+    wxAssociateWinWithHandle( hWnd
+                             ,(wxWindow*)this
+                            );
+    if (!wxCheckWindowWndProc( hWnd
+                              ,(WXFARPROC)wxWndProc
+                             ))
+    {
+        m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
+    }
+    else
+    {
+        m_fnOldWndProc = (WXFARPROC)NULL;
+    }
 } // end of wxWindowOS2::SubclassWin
 
 void wxWindowOS2::UnsubclassWin()
 } // end of wxWindowOS2::SubclassWin
 
 void wxWindowOS2::UnsubclassWin()
@@ -1531,10 +1476,65 @@ void wxWindowOS2::DoGetClientSize(
     RECTL                           vRect;
 
    ::WinQueryWindowRect(hWnd, &vRect);
     RECTL                           vRect;
 
    ::WinQueryWindowRect(hWnd, &vRect);
+    if (IsKindOf(CLASSINFO(wxDialog)))
+    {
+        RECTL                       vTitle;
+        HWND                        hWndTitle;
+        //
+        // For a Dialog we have to explicitly request the client portion.
+        // For a Frame the hWnd IS the client window
+        //
+        hWndTitle = ::WinWindowFromID(hWnd, FID_TITLEBAR);
+        if (::WinQueryWindowRect(hWndTitle, &vTitle))
+        {
+            if (vTitle.yTop - vTitle.yBottom == 0)
+            {
+                //
+                // Dialog has not been created yet, use a default
+                //
+                vTitle.yTop = 20;
+            }
+            vRect.yTop -= (vTitle.yTop - vTitle.yBottom);
+        }
+
+        ULONG                       uStyle = ::WinQueryWindowULong(hWnd, QWL_STYLE);
+
+        //
+        // Deal with borders
+        //
+        if (uStyle & FCF_DLGBORDER)
+        {
+            vRect.xLeft += 4;
+            vRect.xRight -= 4;
+            vRect.yTop -= 4;
+            vRect.yBottom += 4;
+        }
+        else if (uStyle & FCF_SIZEBORDER)
+        {
+            vRect.xLeft += 4;
+            vRect.xRight -= 4;
+            vRect.yTop -= 4;
+            vRect.yBottom += 4;
+        }
+        else if (uStyle & FCF_BORDER)
+        {
+            vRect.xLeft += 2;
+            vRect.xRight -= 2;
+            vRect.yTop -= 2;
+            vRect.yBottom += 2;
+        }
+        else // make some kind of adjustment or top sizers ram into the titlebar!
+        {
+            vRect.xLeft += 3;
+            vRect.xRight -= 3;
+            vRect.yTop -= 3;
+            vRect.yBottom += 3;
+        }
+    }
     if (pWidth)
     if (pWidth)
-        *pWidth  = vRect.xRight;
+        *pWidth  = vRect.xRight - vRect.xLeft;
     if (pHeight)
     if (pHeight)
-        *pHeight = vRect.yTop;
+        *pHeight = vRect.yTop - vRect.yBottom;
 } // end of wxWindowOS2::DoGetClientSize
 
 void wxWindowOS2::DoMoveWindow(
 } // end of wxWindowOS2::DoGetClientSize
 
 void wxWindowOS2::DoMoveWindow(
@@ -1548,7 +1548,7 @@ void wxWindowOS2::DoMoveWindow(
     HWND                            hParent;
     wxWindow*                       pParent = GetParent();
 
     HWND                            hParent;
     wxWindow*                       pParent = GetParent();
 
-    if (pParent)
+    if (pParent && !IsKindOf(CLASSINFO(wxDialog)))
     {
         int                         nOS2Height = GetOS2ParentHeight(pParent);
 
     {
         int                         nOS2Height = GetOS2ParentHeight(pParent);
 
@@ -1610,7 +1610,7 @@ void wxWindowOS2::DoSetSize(
     int                             nY2 = nY;
     wxWindow*                       pParent = (wxWindow*)GetParent();
 
     int                             nY2 = nY;
     wxWindow*                       pParent = (wxWindow*)GetParent();
 
-    if (pParent)
+    if (pParent && !IsKindOf(CLASSINFO(wxDialog)))
     {
         int                         nOS2Height = GetOS2ParentHeight(pParent);
 
     {
         int                         nOS2Height = GetOS2ParentHeight(pParent);
 
@@ -1947,8 +1947,8 @@ static void wxYieldForCommandsOnly()
     //
     QMSG                            vMsg;
 
     //
     QMSG                            vMsg;
 
-    while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND,
-           WM_COMMAND,PM_REMOVE) && vMsg.msg != WM_QUIT)
+    while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE)
+           && vMsg.msg != WM_QUIT)
     {
         wxTheApp->DoMessage((WXMSG*)&vMsg);
     }
     {
         wxTheApp->DoMessage((WXMSG*)&vMsg);
     }
@@ -1962,9 +1962,10 @@ bool wxWindowOS2::DoPopupMenu(
 , int                               nY
 )
 {
 , int                               nY
 )
 {
-    HWND                            hWnd = GetHwnd();
-    HWND                            hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
+    HWND                            hWndOwner = GetHwnd();
+    HWND                            hWndParent = GetHwnd();
     HWND                            hMenu = GetHmenuOf(pMenu);
     HWND                            hMenu = GetHmenuOf(pMenu);
+    bool                            bIsWaiting = TRUE;
 
     pMenu->SetInvokingWindow(this);
     pMenu->UpdateUI();
 
     pMenu->SetInvokingWindow(this);
     pMenu->UpdateUI();
@@ -1975,21 +1976,25 @@ bool wxWindowOS2::DoPopupMenu(
     wxCurrentPopupMenu = pMenu;
 
     ::WinPopupMenu( hWndParent
     wxCurrentPopupMenu = pMenu;
 
     ::WinPopupMenu( hWndParent
-                   ,hWnd
+                   ,hWndOwner
                    ,hMenu
                    ,nX
                    ,nY
                    ,0L
                    ,hMenu
                    ,nX
                    ,nY
                    ,0L
-                   ,PU_MOUSEBUTTON2DOWN | PU_MOUSEBUTTON2 | PU_KEYBOARD
+                   ,PU_HCONSTRAIN | PU_VCONSTRAIN | PU_MOUSEBUTTON2DOWN | PU_MOUSEBUTTON2
                   );
                   );
-    // we need to do it righ now as otherwise the events are never going to be
-    // sent to wxCurrentPopupMenu from ;()
-    //
-    // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
-    // help and we'd still need wxYieldForCommandsOnly() as the menu may be
-    // destroyed as soon as we return (it can be a local variable in the caller
-    // for example) and so we do need to process the event immediately
-    wxYieldForCommandsOnly();
+    while(bIsWaiting)
+    {
+        QMSG                        vMsg;
+
+        while (::WinPeekMsg(vHabmain, &vMsg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE)
+               && vMsg.msg != WM_QUIT)
+        {
+            wxTheApp->DoMessage((WXMSG*)&vMsg);
+        }
+        if (vMsg.msg == WM_DESTROY || vMsg.msg == WM_QUIT)
+            break;
+    }
     wxCurrentPopupMenu = NULL;
 
     pMenu->SetInvokingWindow(NULL);
     wxCurrentPopupMenu = NULL;
 
     pMenu->SetInvokingWindow(NULL);
@@ -2210,6 +2215,14 @@ bool wxWindowOS2::OS2TranslateMessage(
 #endif //wxUSE_ACCEL
 } // end of wxWindowOS2::OS2TranslateMessage
 
 #endif //wxUSE_ACCEL
 } // end of wxWindowOS2::OS2TranslateMessage
 
+bool wxWindowOS2::OS2ShouldPreProcessMessage(
+  WXMSG*                            pMsg
+)
+{
+    // preprocess all messages by default
+    return TRUE;
+} // end of wxWindowOS2::OS2ShouldPreProcessMessage
+
 // ---------------------------------------------------------------------------
 // message params unpackers
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
 // message params unpackers
 // ---------------------------------------------------------------------------
@@ -2396,6 +2409,32 @@ MRESULT wxWindowOS2::OS2WindowProc(
                                    );
             break;
 
                                    );
             break;
 
+        case WM_WINDOWPOSCHANGED:
+
+            //
+            // Dialogs under OS/2 do not get WM_SIZE events at all.
+            // Instead they get this, which can function much like WM_SIZE
+            // PSWP contains the new sizes and positioning, PSWP+1 the old
+            // We use this because ADJUSTWINDOWPOS comes BEFORE the new
+            // position is added and our auto layout does a WinQueryWindowRect
+            // to get the CURRENT client size.  That is the size used to position
+            // child controls, so we need to already be sized
+            // in order to get the child controls positoned properly.
+            //
+            if (IsKindOf(CLASSINFO(wxDialog)))
+            {
+                PSWP                pSwp = (PSWP)PVOIDFROMMP(wParam);
+                PSWP                pSwp2 = pSwp++;
+
+                if (!(pSwp->cx == pSwp2->cx &&
+                      pSwp->cy == pSwp2->cy))
+                    bProcessed = HandleSize( pSwp->cx
+                                            ,pSwp->cy
+                                            ,(WXUINT)lParam
+                                           );
+            }
+            break;
+
         case WM_ACTIVATE:
             {
                 WXWORD              wState;
         case WM_ACTIVATE:
             {
                 WXWORD              wState;
@@ -2721,12 +2760,16 @@ MRESULT wxWindowOS2::OS2WindowProc(
 #endif // __WXDEBUG__
         if (IsKindOf(CLASSINFO(wxFrame)))
             mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam);
 #endif // __WXDEBUG__
         if (IsKindOf(CLASSINFO(wxFrame)))
             mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam);
+        else if (IsKindOf(CLASSINFO(wxDialog)))
+            mResult = ::WinDefDlgProc( m_hWnd, uMsg, wParam, lParam);
         else
             mResult = OS2DefWindowProc(uMsg, wParam, lParam);
     }
     return mResult;
 } // end of wxWindowOS2::OS2WindowProc
 
         else
             mResult = OS2DefWindowProc(uMsg, wParam, lParam);
     }
     return mResult;
 } // end of wxWindowOS2::OS2WindowProc
 
+#ifndef __EMX__
+// clashes with wxDlgProc in toplevel.cpp?
 //
 // Dialog window proc
 //
 //
 // Dialog window proc
 //
@@ -2753,6 +2796,7 @@ MRESULT wxDlgProc(
         return (MRESULT)0;
     }
 } // end of wxDlgProc
         return (MRESULT)0;
     }
 } // end of wxDlgProc
+#endif
 
 wxWindow* wxFindWinFromHandle(
   WXHWND                            hWnd
 
 wxWindow* wxFindWinFromHandle(
   WXHWND                            hWnd
@@ -2811,40 +2855,6 @@ void wxWindowOS2::OS2DestroyWindow()
 {
 }
 
 {
 }
 
-void wxWindowOS2::OS2DetachWindowMenu()
-{
-#ifndef __WXUNIVERSAL__
-    if (m_hMenu)
-    {
-        HMENU                       hMenu = (HMENU)m_hMenu;
-
-        int                         nN = (int)::WinSendMsg(hMenu, MM_QUERYITEMCOUNT, 0, 0);
-        int                         i;
-
-        for (i = 0; i < nN; i++)
-        {
-            wxChar                   zBuf[100];
-            int                      nChars = (int)::WinSendMsg( hMenu
-                                                                ,MM_QUERYITEMTEXT
-                                                                ,MPFROM2SHORT(i, nN)
-                                                                ,zBuf
-                                                               );
-            if (!nChars)
-            {
-                wxLogLastError(wxT("GetMenuString"));
-                continue;
-            }
-
-            if (wxStrcmp(zBuf, wxT("&Window")) == 0)
-            {
-                ::WinSendMsg(hMenu, MM_DELETEITEM, MPFROM2SHORT(i, TRUE), 0);
-                break;
-            }
-        }
-    }
-#endif // __WXUNIVERSAL__
-} // end of wxWindowOS2::OS2DetachWindowMenu
-
 bool wxWindowOS2::OS2GetCreateWindowCoords(
   const wxPoint&                    rPos
 , const wxSize&                     rSize
 bool wxWindowOS2::OS2GetCreateWindowCoords(
   const wxPoint&                    rPos
 , const wxSize&                     rSize
@@ -2966,17 +2976,22 @@ bool wxWindowOS2::OS2Create(
     //
     if (pParent)
     {
     //
     if (pParent)
     {
-        if (IsKindOf(CLASSINFO(wxStatusBar)) &&
-            pParent->IsKindOf(CLASSINFO(wxFrame)))
+        if ( pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)) ||
+             pParent->IsKindOf(CLASSINFO(wxScrolledWindow))
+           )
         {
         {
-            RECTL                   vRect;
-            wxFrame*                pFrame = wxDynamicCast(pParent, wxFrame);
+            if (IsKindOf(CLASSINFO(wxStatusBar)) &&
+                pParent->IsKindOf(CLASSINFO(wxFrame)))
+            {
+                RECTL               vRect;
+                wxFrame*            pFrame = wxDynamicCast(pParent, wxFrame);
 
 
-            ::WinQueryWindowRect((HWND)pFrame->GetFrame(), &vRect);
-            nY = vRect.yTop - (nY + nHeight);
+                ::WinQueryWindowRect((HWND)pFrame->GetFrame(), &vRect);
+                nY = vRect.yTop - (nY + nHeight);
+            }
+            else
+                nY = pParent->GetSize().y - (nY + nHeight);
         }
         }
-        else
-            nY = pParent->GetSize().y - (nY + nHeight);
     }
     else
     {
     }
     else
     {
@@ -3086,6 +3101,13 @@ bool wxWindowOS2::HandleSetFocus(
   WXHWND                            WXUNUSED(hWnd)
 )
 {
   WXHWND                            WXUNUSED(hWnd)
 )
 {
+    //
+    // Notify the parent keeping track of focus for the kbd navigation
+    // purposes that we got it
+    //
+    wxChildFocusEvent               vEventFocus((wxWindow *)this);
+    (void)GetEventHandler()->ProcessEvent(vEventFocus);
+
 #if wxUSE_CARET
     //
     // Deal with caret
 #if wxUSE_CARET
     //
     // Deal with caret
@@ -4087,7 +4109,7 @@ int wxWindowOS2::GetOS2ParentHeight(
     // Case 1
     //
     if (pParent->IsKindOf(CLASSINFO(wxDialog)))
     // Case 1
     //
     if (pParent->IsKindOf(CLASSINFO(wxDialog)))
-        return(pParent->GetSize().y);
+        return(pParent->GetClientSize().y);
 
     //
     // Case 2 -- if we are one of the separately built standard Frame
 
     //
     // Case 2 -- if we are one of the separately built standard Frame