]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/window.cpp
Reverted wxString members to const wxChar * for struct BugsGridData
[wxWidgets.git] / src / os2 / window.cpp
index 8170ce44bdcf8136c681df9e10037cb791392ced..a821b547ba3e1bf793b3b0888167b903d0e7a49e 100644 (file)
@@ -715,8 +715,8 @@ void wxWindow::SubclassWin(
 
     wxAssociateWinWithHandle(hwnd, this);
 
-    m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, wxWndProc);
-    ::WinSetWindowULong(hwnd, QWS_USER, wxWndProc);
+    m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
+    ::WinSetWindowULong(hwnd, QWS_USER, (ULONG)wxWndProc);
 } // end of wxWindow::SubclassWin
 
 void wxWindow::UnsubclassWin()
@@ -767,11 +767,11 @@ WXDWORD wxWindow::MakeExtendedStyle(
 //
 WXDWORD wxWindow::Determine3DEffects(
   WXDWORD                           dwDefaultBorderStyle
-, YBool*                            pbWant3D
+, bool*                             pbWant3D
 ) const
 {
-    WXDWORD                         dwStyle = 0L; 
-   
+    WXDWORD                         dwStyle = 0L;
+
     //
     // Native PM does not have any specialize 3D effects like WIN32 does
     //
@@ -853,7 +853,7 @@ void wxWindow::OnIdle(
 
             if (::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) != 0)
                 nState |= VK_SHIFT;
-            if (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) != 0;
+            if (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) != 0);
                 nState |= VK_CTRL;
 
             wxMouseEvent            rEvent(wxEVT_LEAVE_WINDOW);
@@ -863,7 +863,7 @@ void wxWindow::OnIdle(
                            ,vPoint.y
                            ,nState
                           );
-            (void)GetEventHandler()->ProcessEvent(event);
+            (void)GetEventHandler()->ProcessEvent(rEvent);
         }
     }
     UpdateWindowUI();
@@ -911,7 +911,7 @@ void wxWindow::Refresh(
             RECTL                   vOs2Rect;
 
             vOs2Rect.xLeft   = pRect->x;
-            vOS2Rect.yTop    = pRect->y;
+            vOs2Rect.yTop    = pRect->y;
             vOs2Rect.xRight  = pRect->x + pRect->width;
             vOs2Rect.yBottom = pRect->y + pRect->height;
 
@@ -931,7 +931,7 @@ void wxWindow::SetDropTarget(
   wxDropTarget*                     pDropTarget
 )
 {
-    if (m_dropTarget != 0) 
+    if (m_dropTarget != 0)
     {
         m_dropTarget->Revoke(m_hWnd);
         delete m_dropTarget;
@@ -953,7 +953,7 @@ void wxWindow::DragAcceptFiles(
     HWND                            hWnd = GetHwnd();
 
     if (hWnd && bAccept)
-        ::DragAcceptDroppedFiles(hWnd, NULL, NULL, DO_COPY, 0L);
+        ::DrgAcceptDroppedFiles(hWnd, NULL, NULL, DO_COPY, 0L);
 } // end of wxWindow::DragAcceptFiles
 
 // ----------------------------------------------------------------------------
@@ -968,7 +968,7 @@ void wxWindow::DoSetToolTip(
 {
     wxWindowBase::DoSetToolTip(pTooltip);
 
-    if (m_pTooltip)
+    if (m_tooltip)
         m_tooltip->SetWindow(this);
 } // end of wxWindow::DoSetToolTip
 
@@ -979,111 +979,151 @@ void wxWindow::DoSetToolTip(
 // ---------------------------------------------------------------------------
 
 // Get total size
-void wxWindow::DoGetSize( int *width, int *height ) const
+void wxWindow::DoGetSize(
+  int*                              pWidth
+, int*                              pHeight
+) const
 {
-    HWND hWnd = GetHwnd();
-    RECT rect;
-    GetWindowRect(hWnd, &rect);
+    HWND                            hWnd = GetHwnd();
+    RECTL                           vRect;
 
-    if ( x )
-        *x = rect.right - rect.left;
-    if ( y )
-        *y = rect.bottom - rect.top;
-}
+    ::WinQueryWindowRect(hWnd, &vRect);
 
-void wxWindow::DoGetPosition( int *x, int *y ) const
+    if (pWidth)
+        *pWidth = vRect.xRight - vRect.xLeft;
+    if (pHeight )
+        // OS/2 PM is backwards from windows
+        *pHeight = vRect.yTop - vRect.yBottom;
+} // end of wxWindow::DoGetSize
+
+void wxWindow::DoGetPosition(
+  int*                              pX
+, int*                              pY
+) const
 {
-    HWND hWnd = GetHwnd();
+    HWND                            hWnd = GetHwnd();
+    RECT                            vRect;
+    POINTL                          vPoint;
 
-    RECT rect;
-    GetWindowRect(hWnd, &rect);
+    ::WinQueryWindowRect(hWnd, &vRect);
 
-    POINT point;
-    point.x = rect.left;
-    point.y = rect.top;
+    vPoint.x = vRect.xLeft;
+    vPoint.y = vRect.yBottom;
 
-    // we do the adjustments with respect to the parent only for the "real"
+    //
+    // We do the adjustments with respect to the parent only for the "real"
     // children, not for the dialogs/frames
-    if ( !IsTopLevel() )
+    //
+    if (!IsTopLevel())
     {
-        HWND hParentWnd = 0;
-        wxWindow *parent = GetParent();
-        if ( parent )
-            hParentWnd = GetWinHwnd(parent);
+        HWND                        hParentWnd = 0;
+        wxWindow*                   pParent = GetParent();
+
+        if (pParent)
+            hParentWnd = GetWinHwnd(pParent);
 
+        //
         // Since we now have the absolute screen coords, if there's a parent we
-        // must subtract its top left corner
-        if ( hParentWnd )
+        // must subtract its bottom left corner
+        //
+        if (hParentWnd)
         {
-            ::ScreenToClient(hParentWnd, &point);
+            RECTL                   vRect2;
+
+            ::WinQueryWindowRect(hParentWnd, &vRect2);
+            vPoint.x -= vRect.xLeft;
+            vPoint.y -= vRect.yBottom;
         }
 
+        //
         // We may be faking the client origin. So a window that's really at (0,
         // 30) may appear (to wxWin apps) to be at (0, 0).
-        wxPoint pt(parent->GetClientAreaOrigin());
-        point.x -= pt.x;
-        point.y -= pt.y;
+        //
+        wxPoint                     vPt(pParent->GetClientAreaOrigin());
+
+        vPoint.x -= vPt.x;
+        vPoint.y -= vPt.y;
     }
 
-    if ( x )
-        *x = point.x;
-    if ( y )
-        *y = point.y;
-}
+    if (pX)
+        *pX = vPoint.x;
+    if  (pY)
+        *pY = vPoint.y;
+} // end of wxWindow::DoGetPosition
 
-void wxWindow::DoScreenToClient( int *x, int *y ) const
+void wxWindow::DoScreenToClient(
+  int*                              pX
+, int*                              pY
+) const
 {
-    POINT pt;
-    if ( x )
-        pt.x = *x;
-    if ( y )
-        pt.y = *y;
+    HWND                            hWnd = GetHwnd();
+    SWP                             vSwp;
 
-    HWND hWnd = GetHwnd();
-    ::ScreenToClient(hWnd, &pt);
+    ::WinQueryWindowPos(hWnd, &vSwp);
 
-    if ( x )
-        *x = pt.x;
-    if ( y )
-        *y = pt.y;
-}
+    if (pX)
+        *pX -= vSwp.x;
+    if (pY)
+        *pY -= vSwp.y;
+} // end of wxWindow::DoScreenToClient
 
-void wxWindow::DoClientToScreen( int *x, int *y ) const
+void wxWindow::DoClientToScreen(
+  int*                              pX
+, int*                              pY
+) const
 {
-    POINT pt;
-    if ( x )
-        pt.x = *x;
-    if ( y )
-        pt.y = *y;
+    HWND                            hWnd = GetHwnd();
+    SWP                             vSwp;
 
-    HWND hWnd = GetHwnd();
-    ::ClientToScreen(hWnd, &pt);
+    ::WinQueryWindowPos(hWnd, &vSwp);
 
-    if ( x )
-        *x = pt.x;
-    if ( y )
-        *y = pt.y;
-}
+    if (pX)
+        *pX += vSwp.x;
+    if (pY)
+        *pY += vSwp.y;
+} // end of wxWindow::DoClientToScreen
 
+//
 // Get size *available for subwindows* i.e. excluding menu bar etc.
-void wxWindow::DoGetClientSize( int *width, int *height ) const
+// Must be a frame type window
+//
+void wxWindow::DoGetClientSize(
+  int*                              pWidth
+, int*                              pHeight
+) const
 {
-    HWND hWnd = GetHwnd();
-    RECT rect;
-    ::GetClientRect(hWnd, &rect);
-    if ( x )
-        *x = rect.right;
-    if ( y )
-        *y = rect.bottom;
-}
+    HWND                            hWnd = GetHwnd();
+    HWND                            hWndClient;
+    RECTL                           vRect;
+
+    hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
+    ::WinQueryWindowRect(hWndClient, &vRect);
 
-void wxWindow::DoMoveWindow(int x, int y, int width, int height)
+    if (pWidth)
+        *pWidth  = vRect.xRight;
+    if (pHeight)
+        *pHeight = vRect.yTop;
+} // end of wxWindow::DoGetClientSize
+
+void wxWindow::DoMoveWindow(
+  int                               nX
+, int                               nY
+, int                               nWidth
+, int                               nHeight
+)
 {
-    if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
+    if ( !::WinSetWindowPos( GetHwnd()
+                            ,HWND_TOP
+                            ,(LONG)nX
+                            ,(LONG)nY
+                            ,(LONG)nWidth
+                            ,(LONG)nHeight
+                            ,SWP_SIZE | SWP_MOVE
+                           ))
     {
         wxLogLastError("MoveWindow");
     }
-}
+} // end of wxWindow::DoMoveWindow
 
 //
 // Set the size of the window: if the dimensions are positive, just use them,
@@ -1095,150 +1135,262 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height)
 // the width/height to best suit our contents, otherwise we reuse the current
 // width/height
 //
-void wxWindow::DoSetSize(int x, int y,
-                         int width, int height,
-                         int sizeFlags)
+void wxWindow::DoSetSize(
+  int                               nX
+, int                               nY
+, int                               nWidth
+, int                               nHeight
+, int                               nSizeFlags
+)
 {
-    // get the current size and position...
-    int currentX, currentY;
-    GetPosition(&currentX, &currentY);
-    int currentW,currentH;
-    GetSize(&currentW, &currentH);
+    //
+    // Get the current size and position...
+    //
+    int                             nCurrentX;
+    int                             nCurrentY;
+    int                             nCurrentWidth;
+    int                             nCurrentHeight;
+    wxSize                          vSize(-1, -1);
+
+    GetPosition( &nCurrentX
+                ,&nCurrentY
+               );
+    GetSize( &nCurrentWidth
+            ,&nCurrentHeight
+           );
 
+    //
     // ... and don't do anything (avoiding flicker) if it's already ok
-    if ( x == currentX && y == currentY &&
-         width == currentW && height == currentH )
+    //
+    if ( nX == nCurrentX &&
+         nY == nCurrentY &&
+         nWidth == nCurrentWidth &&
+         nHeight == nCurrentHeight
+       )
     {
         return;
     }
 
-    if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
-        x = currentX;
-    if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
-        y = currentY;
+    if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+        nX = nCurrentX;
+    if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+        nY = nCurrentY;
 
-    AdjustForParentClientOrigin(x, y, sizeFlags);
+    AdjustForParentClientOrigin( nX
+                                ,nY
+                                ,nSizeFlags
+                               );
 
-    wxSize size(-1, -1);
-    if ( width == -1 )
+    if (nWidth == -1)
     {
-        if ( sizeFlags & wxSIZE_AUTO_WIDTH )
+        if (nSizeFlags & wxSIZE_AUTO_WIDTH)
         {
-            size = DoGetBestSize();
-            width = size.x;
+            vSize  = DoGetBestSize();
+            nWidth = vSize.x;
         }
         else
         {
-            // just take the current one
-            width = currentW;
+            //
+            // Just take the current one
+            //
+            nWidth = nCurrentWidth;
         }
     }
 
-    if ( height == -1 )
+    if (nHeight == -1)
     {
-        if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
+        if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
         {
-            if ( size.x == -1 )
+            if (vSize.x == -1)
             {
-                size = DoGetBestSize();
+                vSize = DoGetBestSize();
             }
-            //else: already called DoGetBestSize() above
-
-            height = size.y;
+            nHeight = vSize.y;
         }
         else
         {
             // just take the current one
-            height = currentH;
+            nHeight = nCurrentHeight;
         }
     }
 
-    DoMoveWindow(x, y, width, height);
-}
+    DoMoveWindow( nX
+                 ,nY
+                 ,nWidth
+                 ,nHeight
+                );
+} // end of wxWindow::DoSetSize
 
-void wxWindow::DoSetClientSize(int width, int height)
+void wxWindow::DoSetClientSize(
+  int                               nWidth
+, int                               nHeight
+)
 {
-    wxWindow *parent = GetParent();
-    HWND hWnd = GetHwnd();
-    HWND hParentWnd = (HWND) 0;
-    if ( parent )
-        hParentWnd = (HWND) parent->GetHWND();
+    wxWindow*                       pParent = GetParent();
+    HWND                            hWnd = GetHwnd();
+    HWND                            hParentWnd = (HWND)0;
+    HWND                            hClientWnd = (HWND)0;
+    RECTL                           vRect;
+    RECT                            vRect2;
+    RECT                            vRect3;
 
-    RECT rect;
-    ::GetClientRect(hWnd, &rect);
+    hClientWnd = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
+    ::WinQueryWindowRect(hClientWnd, &vRect2);
 
-    RECT rect2;
-    GetWindowRect(hWnd, &rect2);
+    if (pParent)
+        hParentWnd = (HWND) pParent->GetHWND();
 
+    ::WinQueryWindowRect(hWnd, &vRect);
+    ::WinQueryWindowRect(hParentWnd, &vRect3);
+    //
     // Find the difference between the entire window (title bar and all)
     // and the client area; add this to the new client size to move the
-    // window
-    int actual_width = rect2.right - rect2.left - rect.right + width;
-    int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
+    // window. OS/2 is backward from windows on height
+    //
+    int                             nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
+    int                             nActualHeight = vRect2.yTop - vRect2.yBottom - vRect.yTop + nHeight;
 
-    // If there's a parent, must subtract the parent's top left corner
+    //
+    // If there's a parent, must subtract the parent's bottom left corner
     // since MoveWindow moves relative to the parent
+    //
+    POINTL                          vPoint;
 
-    POINT point;
-    point.x = rect2.left;
-    point.y = rect2.top;
-    if ( parent )
+    vPoint.x = vRect2.xLeft;
+    vPoint.y = vRect2.yBottom;
+    if (pParent)
     {
-        ::ScreenToClient(hParentWnd, &point);
+        vPoint.x -= vRect3.xLeft;
+        vPoint.y -= vRect3.yBottom;
     }
 
-    DoMoveWindow(point.x, point.y, actual_width, actual_height);
+    DoMoveWindow( vPoint.x
+                 ,vPoint.y
+                 ,nActualWidth
+                 ,nActualHeight
+                );
 
-    wxSizeEvent event(wxSize(width, height), m_windowId);
-    event.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(event);
-}
+    wxSizeEvent                     vEvent( wxSize( nWidth
+                                                  ,nHeight
+                                                 )
+                                           ,m_windowId
+                                          );
+
+    vEvent.SetEventObject(this);
+    GetEventHandler()->ProcessEvent(vEvent);
+} // end of wxWindow::DoSetClientSize
 
 wxPoint wxWindow::GetClientAreaOrigin() const
 {
     return wxPoint(0, 0);
-}
+} // end of wxWindow::GetClientAreaOrigin
 
-void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
+void wxWindow::AdjustForParentClientOrigin(
+  int&                              rX
+, int&                              rY
+, int                               nSizeFlags
+)
 {
-    // don't do it for the dialogs/frames - they float independently of their
+    //
+    // Don't do it for the dialogs/frames - they float independently of their
     // parent
-    if ( !IsTopLevel() )
+    //
+    if (!IsTopLevel())
     {
-        wxWindow *parent = GetParent();
-        if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
+        wxWindow*                   pParent = GetParent();
+
+        if (!(nSizeFlags & wxSIZE_NO_ADJUSTMENTS) && pParent)
         {
-            wxPoint pt(parent->GetClientAreaOrigin());
-            x += pt.x; y += pt.y;
+            wxPoint                 vPoint(pParent->GetClientAreaOrigin());
+            rX += vPoint.x;
+            rY += vPoint.y;
         }
     }
-}
+} // end of wxWindow::AdjustForParentClientOrigin
 
 // ---------------------------------------------------------------------------
 // text metrics
 // ---------------------------------------------------------------------------
 
-int  wxWindow::GetCharHeight() const
+int wxWindow::GetCharHeight() const
 {
-    // TODO:
-    return(1);
-}
+    HPS                             hPs;
+    FONTMETRICS                     vFontMetrics;
+    BOOL                            bRc;
 
-int  wxWindow::GetCharWidth() const
+    hPs = ::WinGetPS(GetHwnd());
+
+    if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
+        return (0);
+    else
+        return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender);
+    ::WinReleasePS(hPs);
+} // end of wxWindow::GetCharHeight
+
+int wxWindow::GetCharWidth() const
 {
-    // TODO:
-    return(1);
-}
+    HPS                             hPs;
+    FONTMETRICS                     vFontMetrics;
+
+    hPs = ::WinGetPS(GetHwnd());
 
-void wxWindow::GetTextExtent( const wxString& string
-                             ,int*            x
-                             ,int*            y
-                             ,int*            descent
-                             ,int*            externalLeading
-                             ,const wxFont*   theFont
-                            ) const
+    if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
+        return (0);
+    else
+        return(vFontMetrics.lAveCharWidth);
+    ::WinReleasePS(hPs);
+} // end of wxWindow::GetCharWidth
+
+void wxWindow::GetTextExtent(
+  const wxString&                   rString
+, int*                              pX
+, int*                              pY
+, int*                              pDescent
+, int*                              pExternalLeading
+, const wxFont*                     pTheFont
+) const
 {
-    // TODO:
+    const wxFont*                   pFontToUse = pTheFont;
+    HPS                             hPs;
+
+    hPs = ::WinGetPS(GetHwnd());
+/*
+// TODO: Will have to play with fonts later
+
+    if (!pFontToUse)
+        pFontToUse = &m_font;
+
+    HFONT                           hFnt = 0;
+    HFONT                           hFfontOld = 0;
+
+    if (pFontToUse && pFontToUse->Ok())
+    {
+        ::GpiCreateLog
+        hFnt = (HFONT)((wxFont *)pFontToUse)->GetResourceHandle(); // const_cast
+        if (hFnt)
+            hFontOld = (HFONT)SelectObject(dc,fnt);
+    }
+
+    SIZE sizeRect;
+    TEXTMETRIC tm;
+    GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
+    GetTextMetrics(dc, &tm);
+
+    if ( fontToUse && fnt && hfontOld )
+        SelectObject(dc, hfontOld);
+
+    ReleaseDC(hWnd, dc);
+
+    if ( x )
+        *x = sizeRect.cx;
+    if ( y )
+        *y = sizeRect.cy;
+    if ( descent )
+        *descent = tm.tmDescent;
+    if ( externalLeading )
+        *externalLeading = tm.tmExternalLeading;
+*/
+    ::WinReleasePS(hPs);
 }
 
 #if wxUSE_CARET && WXWIN_COMPATIBILITY
@@ -1246,35 +1398,60 @@ void wxWindow::GetTextExtent( const wxString& string
 // Caret manipulation
 // ---------------------------------------------------------------------------
 
-void wxWindow::CreateCaret(int w, int h)
+void wxWindow::CreateCaret(
+  int                               nWidth
+, int                               nHeight
+)
 {
-    // TODO:
-}
+    SetCaret(new wxCaret( this
+                         ,nWidth
+                         ,nHeight
+                        ));
+} // end of wxWindow::CreateCaret
 
-void wxWindow::CreateCaret(const wxBitmap *bitmap)
+void wxWindow::CreateCaret(
+  const wxBitmap*                   pBitmap
+)
 {
-    // TODO:
-}
+    wxFAIL_MSG("not implemented");
+} // end of wxWindow::CreateCaret
 
-void wxWindow::ShowCaret(bool show)
+void wxWindow::ShowCaret(
+  bool                              bShow
+)
 {
-    // TODO:
-}
+    wxCHECK_RET( m_caret, "no caret to show" );
+
+    m_caret->Show(bShow);
+} // end of wxWindow::ShowCaret
 
 void wxWindow::DestroyCaret()
 {
-    // TODO:
-}
+    SetCaret(NULL);
+} // end of wxWindow::DestroyCaret
 
-void wxWindow::SetCaretPos(int x, int y)
+void wxWindow::SetCaretPos(
+  int                               nX
+, int                               nY)
 {
-    // TODO:
-}
+    wxCHECK_RET( m_caret, "no caret to move" );
+
+    m_caret->Move( nX
+                  ,nY
+                 );
+} // end of wxWindow::SetCaretPos
 
-void wxWindow::GetCaretPos(int *x, int *y) const
+void wxWindow::GetCaretPos(
+  int*                              pX
+, int*                              pY
+) const
 {
-    // TODO:
-}
+    wxCHECK_RET( m_caret, "no caret to get position of" );
+
+    m_caret->GetPosition( pX
+                         ,pY
+                        );
+} // end of wxWindow::GetCaretPos
 
 #endif //wxUSE_CARET