]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
New Refresh()/Update() behaviour. As expected, scrolling
[wxWidgets.git] / src / os2 / window.cpp
index 30ac8d5c44d2c53d01cb50af67730f0eb454386d..681b0b3451b22c8b8ddbb138054f4205c1a45e70 100644 (file)
@@ -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
@@ -830,7 +764,7 @@ void wxWindowOS2::SetScrollbar(
     int                             nPageSize = nThumbVisible;
     SBCDATA                         vInfo;
     HWND                            hWnd = GetHwnd();
     int                             nPageSize = nThumbVisible;
     SBCDATA                         vInfo;
     HWND                            hWnd = GetHwnd();
-    ULONG                           ulStyle = WS_VISIBLE | WS_SYNCPAINT;
+    ULONG                           ulStyle = WS_VISIBLE;
     RECTL                           vRect;
 
     ::WinQueryWindowRect(hWnd, &vRect);
     RECTL                           vRect;
 
     ::WinQueryWindowRect(hWnd, &vRect);
@@ -864,7 +798,7 @@ void wxWindowOS2::SetScrollbar(
                                                     ,20
                                                     ,hWnd
                                                     ,HWND_TOP
                                                     ,20
                                                     ,hWnd
                                                     ,HWND_TOP
-                                                    ,FID_HORZSCROLL
+                                                    ,60000
                                                     ,&vInfo
                                                     ,NULL
                                                    );
                                                     ,&vInfo
                                                     ,NULL
                                                    );
@@ -914,7 +848,7 @@ void wxWindowOS2::SetScrollbar(
                                                     ,vRect.yTop - (vRect.yBottom + 20)
                                                     ,hWnd
                                                     ,HWND_TOP
                                                     ,vRect.yTop - (vRect.yBottom + 20)
                                                     ,hWnd
                                                     ,HWND_TOP
-                                                    ,FID_VERTSCROLL
+                                                    ,60001
                                                     ,&vInfo
                                                     ,NULL
                                                    );
                                                     ,&vInfo
                                                     ,NULL
                                                    );
@@ -958,10 +892,13 @@ void wxWindowOS2::ScrollWindow(
 , const wxRect*                     pRect
 )
 {
 , const wxRect*                     pRect
 )
 {
+    nDy *= -1; // flip the sign of Dy as OS/2 is opposite Windows.
     RECTL                           vRect;
     RECTL                           vRect2;
     RECTL                           vRect;
     RECTL                           vRect2;
+    RECTL                           vRectHorz;
+    RECTL                           vRectVert;
+    RECTL                           vRectChild;
 
 
-    nDy *= -1; // flip the sign of Dy as OS/2 is opposite wxWin.
     if (pRect)
     {
         vRect2.xLeft   = pRect->x;
     if (pRect)
     {
         vRect2.xLeft   = pRect->x;
@@ -971,36 +908,28 @@ void wxWindowOS2::ScrollWindow(
     }
     else
     {
     }
     else
     {
-        ::WinQueryWindowRect(GetHwnd(), &vRect2);
-        ::WinQueryWindowRect(m_hWndScrollBarHorz, &vRect);
+        ::WinQueryWindowRect(GetHwnd(), &vRect);
+        ::WinQueryWindowRect(m_hWndScrollBarHorz, &vRectHorz);
         vRect2.yBottom += vRect.yTop - vRect.yBottom;
         vRect2.yBottom += vRect.yTop - vRect.yBottom;
-        ::WinQueryWindowRect(m_hWndScrollBarVert, &vRect);
+        ::WinQueryWindowRect(m_hWndScrollBarVert, &vRectVert);
         vRect2.xRight -= vRect.xRight - vRect.xLeft;
 
     }
         vRect2.xRight -= vRect.xRight - vRect.xLeft;
 
     }
-    if (pRect)
-        ::WinScrollWindow( GetHwnd()
-                          ,(LONG)nDx
-                          ,(LONG)nDy
-                          ,&vRect2
-                          ,NULL
-                          ,NULLHANDLE
-                          ,NULL
-                          ,SW_INVALIDATERGN
-                         );
-    else
-        ::WinScrollWindow( GetHwnd()
-                          ,nDx
-                          ,nDy
-                          ,NULL
-                          ,NULL
-                          ,NULLHANDLE
-                          ,NULL
-                          ,SW_INVALIDATERGN
-                         );
+    ::WinScrollWindow( GetHwnd()
+                      ,(LONG)nDx
+                      ,(LONG)nDy
+                      ,&vRect
+                      ,NULL
+                      ,NULLHANDLE
+                      ,NULL
+                      ,SW_INVALIDATERGN
+                     );
+    ::WinInvalidateRect(m_hWndScrollBarHorz, &vRectHorz, FALSE);
+    ::WinInvalidateRect(m_hWndScrollBarVert, &vRectVert, FALSE);
 
     //
     // Move the children
 
     //
     // Move the children
+    //
     wxWindowList::Node*             pCurrent = GetChildren().GetFirst();
     SWP                             vSwp;
 
     wxWindowList::Node*             pCurrent = GetChildren().GetFirst();
     SWP                             vSwp;
 
@@ -1011,31 +940,53 @@ void wxWindowOS2::ScrollWindow(
         if (pChildWin->GetHWND() != NULLHANDLE)
         {
             ::WinQueryWindowPos(pChildWin->GetHWND(), &vSwp);
         if (pChildWin->GetHWND() != NULLHANDLE)
         {
             ::WinQueryWindowPos(pChildWin->GetHWND(), &vSwp);
-            ::WinQueryWindowRect(pChildWin->GetHWND(), &vRect);
-            if (pChildWin->GetHWND() == m_hWndScrollBarVert ||
-                pChildWin->GetHWND() == m_hWndScrollBarHorz)
+            ::WinQueryWindowRect(pChildWin->GetHWND(), &vRectChild);
+            if (pChildWin->IsKindOf(CLASSINFO(wxControl)))
             {
             {
-                ::WinSetWindowPos( pChildWin->GetHWND()
-                                  ,HWND_TOP
-                                  ,vSwp.x + nDx
-                                  ,vSwp.y + nDy
-                                  ,0
-                                  ,0
-                                  ,SWP_MOVE | SWP_SHOW | SWP_ZORDER
-                                 );
+                wxControl*          pCtrl;
+
+                //
+                // Must deal with controls that have margins like ENTRYFIELD.  The SWP
+                // struct of such a control will have and origin offset from its intended
+                // position by the width of the margins.
+                //
+                pCtrl = wxDynamicCast(pChildWin, wxControl);
+                vSwp.y -= pCtrl->GetYComp();
+                vSwp.x -= pCtrl->GetXComp();
             }
             }
-            else
+            ::WinSetWindowPos( pChildWin->GetHWND()
+                              ,HWND_BOTTOM
+                              ,vSwp.x + nDx
+                              ,vSwp.y + nDy
+                              ,0
+                              ,0
+                              ,SWP_MOVE | SWP_ZORDER
+                             );
+            if (pChildWin->IsKindOf(CLASSINFO(wxRadioBox)))
             {
             {
-                ::WinSetWindowPos( pChildWin->GetHWND()
-                                  ,HWND_BOTTOM
-                                  ,vSwp.x + nDx
-                                  ,vSwp.y + nDy
-                                  ,0
-                                  ,0
-                                  ,SWP_MOVE | SWP_ZORDER
-                                 );
-                ::WinInvalidateRect(pChildWin->GetHWND(), &vRect, FALSE);
+                wxRadioBox*         pRadioBox;
+
+                pRadioBox = wxDynamicCast(pChildWin, wxRadioBox);
+                pRadioBox->AdjustButtons( (int)vSwp.x + nDx
+                                         ,(int)vSwp.y + nDy
+                                         ,(int)vSwp.cx
+                                         ,(int)vSwp.cy
+                                         ,pRadioBox->GetSizeFlags()
+                                        );
             }
             }
+            if (pChildWin->IsKindOf(CLASSINFO(wxSlider)))
+            {
+                wxSlider*           pSlider;
+
+                pSlider = wxDynamicCast(pChildWin, wxSlider);
+                pSlider->AdjustSubControls( (int)vSwp.x + nDx
+                                           ,(int)vSwp.y + nDy
+                                           ,(int)vSwp.cx
+                                           ,(int)vSwp.cy
+                                           ,pSlider->GetSizeFlags()
+                                          );
+            }
+            ::WinInvalidateRect(pChildWin->GetHWND(), &vRectChild, FALSE);
         }
         pCurrent = pCurrent->GetNext();
     }
         }
         pCurrent = pCurrent->GetNext();
     }
@@ -1051,9 +1002,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()
@@ -2002,8 +1964,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);
     }
@@ -2017,9 +1979,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();
@@ -2030,23 +1993,27 @@ 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_MOUSEBUTTON1 | PU_KEYBOARD
                   );
                   );
-    // 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();
-    wxCurrentPopupMenu = NULL;
 
 
+    while(bIsWaiting)
+    {
+        QMSG                            vMsg;
+        BOOL                            bRc = ::WinGetMsg(vHabmain, &vMsg, HWND(NULL), 0, 0);
+
+        if (vMsg.msg == WM_MENUEND || vMsg.msg == WM_COMMAND)
+        {
+            bIsWaiting = FALSE;
+        }
+        ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
+
+    }
+    wxCurrentPopupMenu = NULL;
     pMenu->SetInvokingWindow(NULL);
     return TRUE;
 } // end of wxWindowOS2::DoPopupMenu
     pMenu->SetInvokingWindow(NULL);
     return TRUE;
 } // end of wxWindowOS2::DoPopupMenu
@@ -2471,7 +2438,7 @@ MRESULT wxWindowOS2::OS2WindowProc(
             // child controls, so we need to already be sized
             // in order to get the child controls positoned properly.
             //
             // child controls, so we need to already be sized
             // in order to get the child controls positoned properly.
             //
-            if (IsKindOf(CLASSINFO(wxDialog)))
+            if (IsKindOf(CLASSINFO(wxDialog)) || IsKindOf(CLASSINFO(wxFrame)))
             {
                 PSWP                pSwp = (PSWP)PVOIDFROMMP(wParam);
                 PSWP                pSwp2 = pSwp++;
             {
                 PSWP                pSwp = (PSWP)PVOIDFROMMP(wParam);
                 PSWP                pSwp2 = pSwp++;
@@ -2482,6 +2449,16 @@ MRESULT wxWindowOS2::OS2WindowProc(
                                             ,pSwp->cy
                                             ,(WXUINT)lParam
                                            );
                                             ,pSwp->cy
                                             ,(WXUINT)lParam
                                            );
+                if (IsKindOf(CLASSINFO(wxFrame)))
+                {
+                    wxFrame*            pFrame = wxDynamicCast(this, wxFrame);
+
+                    if (pFrame)
+                    {
+                        if (pFrame->GetStatusBar())
+                            pFrame->PositionStatusBar();
+                    }
+                }
             }
             break;
 
             }
             break;
 
@@ -2548,8 +2525,8 @@ MRESULT wxWindowOS2::OS2WindowProc(
         case WM_BUTTON3MOTIONEND:
         case WM_BUTTON3MOTIONSTART:
             {
         case WM_BUTTON3MOTIONEND:
         case WM_BUTTON3MOTIONSTART:
             {
-                short x = LOWORD(lParam);
-                short y = HIWORD(lParam);
+                short x = LOWORD(wParam);
+                short y = HIWORD(wParam);
 
                 bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam);
             }
 
                 bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam);
             }
@@ -3026,17 +3003,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
     {