X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/445c7bca97672580a479237cfb3933fe70f8203f..c3e646b47f99fd832ab29c07554b533ea8a807e4:/src/os2/dc.cpp diff --git a/src/os2/dc.cpp b/src/os2/dc.cpp index 47ef5b4fc2..deb5403652 100644 --- a/src/os2/dc.cpp +++ b/src/os2/dc.cpp @@ -146,13 +146,13 @@ wxDC::wxDC(void) m_nDCCount = 0; m_hOldPS = NULL; m_hPS = NULL; - m_bIsPaintTime = FALSE;// True at Paint Time -}; + m_bIsPaintTime = FALSE; // True at Paint Time + m_brush.GetColour().Set("WHITE"); +} wxDC::~wxDC(void) { - // TODO: -}; +} // This will select current objects out of the DC, // which is what you have to do before deleting the @@ -204,34 +204,73 @@ void wxDC::SelectOldObjects(WXHDC dc) // clipping // --------------------------------------------------------------------------- -#define DO_SET_CLIPPING_BOX() \ -{ \ - RECT rect; \ - \ - GetClipBox(GetHdc(), &rect); \ - \ - m_clipX1 = (wxCoord) XDEV2LOG(rect.left); \ - m_clipY1 = (wxCoord) YDEV2LOG(rect.top); \ - m_clipX2 = (wxCoord) XDEV2LOG(rect.right); \ - m_clipY2 = (wxCoord) YDEV2LOG(rect.bottom); \ -} - -void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y - ,wxCoord width, wxCoord height - ) +#define DO_SET_CLIPPING_BOX() \ +{ \ + RECTL rect; \ + \ + ::GpiQueryClipBox(m_hPS, &rect); \ + \ + m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \ + m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \ + m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \ + m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \ +} + +void wxDC::DoSetClippingRegion( + wxCoord x +, wxCoord y +, wxCoord width +, wxCoord height +) { - // TODO -} + RECTL vRect; + + m_clipping = TRUE; + vRect.xLeft = XLOG2DEV(x); + vRect.yTop = YLOG2DEV(m_vRclPaint.yTop - y); + vRect.xRight = XLOG2DEV(x + width); + vRect.yBottom = YLOG2DEV(m_vRclPaint.yTop - (y + height)); + ::GpiIntersectClipRectangle(m_hPS, &vRect); + DO_SET_CLIPPING_BOX() +} // end of wxDC::DoSetClippingRegion -void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) +void wxDC::DoSetClippingRegionAsRegion( + const wxRegion& rRegion +) { - // TODO -} + wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region")); + HRGN hRgnOld; + + m_clipping = TRUE; + ::GpiSetClipRegion( m_hPS + ,(HRGN)rRegion.GetHRGN() + ,&hRgnOld + ); + DO_SET_CLIPPING_BOX() +} // end of wxDC::DoSetClippingRegionAsRegion void wxDC::DestroyClippingRegion(void) { - // TODO: -}; + if (m_clipping && m_hPS) + { + HRGN hRgnOld; + RECTL vRect; + + // TODO: this should restore the previous clipped region + // so that OnPaint processing works correctly, and + // the update doesn't get destroyed after the first + // DestroyClippingRegion + vRect.xLeft = XLOG2DEV(0); + vRect.yTop = YLOG2DEV(32000); + vRect.xRight = XLOG2DEV(32000); + vRect.yBottom = YLOG2DEV(0); + + HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect); + + ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld); + } + m_clipping = FALSE; +} // end of wxDC::DestroyClippingRegion // --------------------------------------------------------------------------- // query capabilities @@ -300,7 +339,7 @@ bool wxDC::DoGetPixel( vPoint.x = vX; vPoint.y = vY; lColor = ::GpiSetPel(m_hPS, &vPoint); - *pCol = lColor; + pCol->Set((unsigned long)lColor); if(lColor>= 0) return(TRUE); else @@ -322,10 +361,9 @@ void wxDC::DoDrawLine( POINTL vPoint[2]; vPoint[0].x = vX1; - vPoint[0].y = vY1; + vPoint[0].y = m_vRclPaint.yTop - vY1; vPoint[1].x = vX2; - vPoint[1].y = vY2; - // ::GpiSetColor(m_hPS,CLR_RED); //DEbug + vPoint[1].y = m_vRclPaint.yTop - vY2; ::GpiMove(m_hPS, &vPoint[0]); ::GpiLine(m_hPS, &vPoint[1]); } @@ -387,19 +425,13 @@ void wxDC::DoDrawArc( dAnglmid = (dAngl1 + dAngl2)/2. + M_PI; vXm = vXc + dRadius * cos(dAnglmid); vYm = vYc + dRadius * sin(dAnglmid); - DoDrawArc( vX1 - ,vY1 - ,vXm - ,vYm - ,vXc - ,vYc + DoDrawArc( vX1, vY1 + ,vXm, vYm + ,vXc, vYc ); - DoDrawArc( vXm - ,vYm - ,vX2 - ,vY2 - ,vXc - ,vYc + DoDrawArc( vXm, vYm + ,vX2, vY2 + ,vXc, vYc ); return; } @@ -423,8 +455,8 @@ void wxDC::DoDrawArc( vPtlPos.x = vX1; // Loads x-coordinate vPtlPos.y = vY1; // Loads y-coordinate ::GpiMove(m_hPS, &vPtlPos); // Sets current position - vPtlArc[0].x = vXm; - vPtlArc[0].y = vYm; + vPtlArc[0].x = vXm; + vPtlArc[0].y = vYm; vPtlArc[1].x = vX2; vPtlArc[1].y = vY2; ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc @@ -475,7 +507,7 @@ void wxDC::DoDrawPoint( POINTL vPoint; vPoint.x = vX; - vPoint.y = vY; + vPoint.y = m_vRclPaint.yTop - vY; ::GpiSetPel(m_hPS, &vPoint); } @@ -590,9 +622,9 @@ void wxDC::DoDrawRectangle( int nIsTRANSPARENT = 0; vPoint[0].x = vX; - vPoint[0].y = vY; + vPoint[0].y = m_vRclPaint.yTop - (vY + vHeight); vPoint[1].x = vX + vWidth; - vPoint[1].y = vY - vHeight; //mustdie !!! ?? + vPoint[1].y = m_vRclPaint.yTop - vY; ::GpiMove(m_hPS, &vPoint[0]); lColor = m_brush.GetColour().GetPixel(); lBorderColor = m_pen.GetColour().GetPixel(); @@ -604,8 +636,7 @@ void wxDC::DoDrawRectangle( if(m_brush.GetStyle() == wxTRANSPARENT) lControl = DRO_OUTLINE; -//EK ::GpiSetColor(m_hPS,lBorderColor); - ::GpiSetColor(m_hPS,CLR_GREEN); + ::GpiSetColor(m_hPS, lColor); ::GpiBox( m_hPS // handle to a presentation space ,lControl // draw the box outline ? or ? ,&vPoint[1] // address of the corner @@ -629,6 +660,11 @@ void wxDC::DoDrawRectangle( ::GpiSetColor( m_hPS ,lColor ); + vPoint[0].x = vX + 1; + vPoint[0].y = m_vRclPaint.yTop - (vY + vHeight) + 1; + vPoint[1].x = vX + vWidth - 2; + vPoint[1].y = m_vRclPaint.yTop - (vY + 2); + ::GpiMove(m_hPS, &vPoint[0]); ::GpiBox( m_hPS ,lControl ,&vPoint[1] @@ -650,9 +686,9 @@ void wxDC::DoDrawRoundedRectangle( LONG lControl; vPoint[0].x = vX; - vPoint[0].y = vY; + vPoint[0].y = YLOG2DEV(vY) - vHeight; vPoint[1].x = vX + vWidth; - vPoint[1].y = vY + vHeight; + vPoint[1].y = vY; ::GpiMove(m_hPS, &vPoint[0]); lControl = DRO_OUTLINEFILL; //DRO_FILL; @@ -925,22 +961,19 @@ void wxDC::SetFont( // if (m_hOldFont) { -// ::SelectObject(GetHdc(), (HFONT) m_hOldFont); m_hOldFont = 0; } - m_font = rFont; - if (!rFont.Ok()) { - if (m_hOldFont) -// ::SelectObject(GetHdc(), (HFONT) m_hOldFont); m_hOldFont = 0; } - if (m_font.Ok() && m_font.GetResourceHandle()) + m_font.SetPS(m_hPS); // this will realize the font + + if (m_font.Ok()) { - HFONT hFont = (HFONT)0; //::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle()); + HFONT hFont = m_font.GetResourceHandle(); if (hFont == (HFONT) NULL) { wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont.")); @@ -948,7 +981,7 @@ void wxDC::SetFont( if (!m_hOldFont) m_hOldFont = (WXHFONT) hFont; } -} +} // end of wxDC::SetFont void wxDC::SetPen( const wxPen& rPen @@ -962,74 +995,65 @@ void wxDC::SetPen( if (!m_pen.Ok()) return; - int nWidth = m_pen.GetWidth(); + if (m_hOldPen) + m_hOldPen = 0L; + m_pen = rPen; - if (nWidth <= 0) - { - nWidth = 1; - } - else + if (!m_pen.Ok()) { - double dW = 0.5 + - ( fabs((double) XLOG2DEVREL(nWidth)) + - fabs((double) YLOG2DEVREL(nWidth)) - ) / 2.0; - nWidth = (int)dW; + if (m_hOldPen) + { + m_pen.SetPS((HPS)m_hOldPen); + } + m_hOldPen = 0L; } - wxColour vColor = m_pen.GetColour(); - ::GpiSetColor( m_hPS - ,vColor.GetPixel() - ); //DEbug ?? - - int nLinetype; - int nStyle = m_pen.GetStyle(); - - nLinetype = LINETYPE_DEFAULT; - switch(nStyle) + if (m_pen.Ok()) { - case wxDOT: - nLinetype = LINETYPE_DOT; - break; - - case wxLONG_DASH: - nLinetype = LINETYPE_LONGDASH; - break; - - case wxSHORT_DASH: - nLinetype = LINETYPE_SHORTDASH; - break; - - case wxDOT_DASH: - nLinetype = LINETYPE_DASHDOT; - break; - - case wxTRANSPARENT: - nLinetype = LINETYPE_INVISIBLE; - break; - - case wxSOLID: - nLinetype = LINETYPE_SOLID; - break; + if (m_pen.GetResourceHandle()) + { + m_pen.SetPS(m_hPS); + if (!m_hOldPen) + m_hOldPen = m_pen.GetPS(); + } } - ::GpiSetLineType( m_hPS - ,nLinetype - ); - - nWidth = m_pen.GetWidth(); - ::GpiSetLineWidth( m_hPS - ,MAKEFIXED( nWidth - ,0 - ) - ); } void wxDC::SetBrush( const wxBrush& rBrush ) { - // TODO -} + wxCHECK_RET( Ok(), wxT("invalid window dc") ); + + if (m_brush == rBrush) + return; + m_brush = rBrush; + if (!m_brush.Ok()) + return; + + if (m_hOldBrush) + m_hOldBrush = 0L; + m_brush = rBrush; + + if (!m_brush.Ok()) + { + if (m_hOldBrush) + { + m_brush.SetPS((HPS)m_hOldBrush); + } + m_hOldBrush = 0L; + } + + if (m_brush.Ok()) + { + if (m_brush.GetResourceHandle()) + { + m_brush.SetPS(m_hPS); + if (!m_hOldBrush) + m_hOldBrush = m_brush.GetPS(); + } + } +} // end of wxDC::SetBrush void wxDC::SetBackground(const wxBrush& brush) { @@ -1104,14 +1128,24 @@ void wxDC::EndPage() wxCoord wxDC::GetCharHeight() const { - // TODO - return(8); + FONTMETRICS vFM; // metrics structure + + ::GpiQueryFontMetrics( m_hPS + ,sizeof(FONTMETRICS) + ,&vFM + ); + return YDEV2LOGREL(vFM.lXHeight); } wxCoord wxDC::GetCharWidth() const { - // TODO - return(8); + FONTMETRICS vFM; // metrics structure + + ::GpiQueryFontMetrics( m_hPS + ,sizeof(FONTMETRICS) + ,&vFM + ); + return XDEV2LOGREL(vFM.lAveCharWidth); } void wxDC::DoGetTextExtent( @@ -1213,9 +1247,25 @@ void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) // TODO: }; -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) +void wxDC::SetDeviceOrigin( + wxCoord x +, wxCoord y +) { - // TODO: + RECTL vRect; + + m_deviceOriginX = x; + m_deviceOriginY = y; + ::GpiQueryPageViewport( m_hPS + ,&vRect + ); + vRect.xLeft += x; + vRect.xRight += x; + vRect.yBottom -= y; + vRect.yTop -= y; + ::GpiSetPageViewport( m_hPS + ,&vRect + ); }; // ---------------------------------------------------------------------------