X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fb46a9a6c6f291806a5fecbb848930c344e17e11..3ad1cd4a67d26b431d163d798f980dfb3628681e:/src/os2/dc.cpp diff --git a/src/os2/dc.cpp b/src/os2/dc.cpp index a5787d1f03..63a91c8b71 100644 --- a/src/os2/dc.cpp +++ b/src/os2/dc.cpp @@ -31,9 +31,7 @@ #include "wx/os2/private.h" -#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) -#endif // --------------------------------------------------------------------------- // constants @@ -44,6 +42,18 @@ static const int VIEWPORT_EXTENT = 1000; static const int MM_POINTS = 9; static const int MM_METRIC = 10; +// usually this is defined in math.h +#ifndef M_PI + static const double M_PI = 3.14159265358979323846; +#endif // M_PI + +// --------------------------------------------------------------------------- +// private functions +// --------------------------------------------------------------------------- + +// convert degrees to radians +static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } + // =========================================================================== // implementation // =========================================================================== @@ -54,17 +64,17 @@ static const int MM_METRIC = 10; wxDC::wxDC(void) { - m_canvas = NULL; + m_pCanvas = NULL; - m_oldBitmap = 0; - m_oldPen = 0; - m_oldBrush = 0; - m_oldFont = 0; - m_oldPalette = 0; + m_hOldBitmap = 0; + m_hOldPen = 0; + m_hOldBrush = 0; + m_hOldFont = 0; + m_hOldPalette = 0; - m_bOwnsDC = FALSE; - m_hDC = 0; - m_hDCCount = 0; + m_bOwnsDC = FALSE; + m_hDC = 0; + m_nDCCount = 0; }; wxDC::~wxDC(void) @@ -79,69 +89,71 @@ void wxDC::SelectOldObjects(WXHDC dc) { if (dc) { - if (m_oldBitmap) + if (m_hOldBitmap) { // ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); - if (m_selectedBitmap.Ok()) + if (m_vSelectedBitmap.Ok()) { - m_selectedBitmap.SetSelectedInto(NULL); + m_vSelectedBitmap.SetSelectedInto(NULL); } } - m_oldBitmap = 0; - if (m_oldPen) + m_hOldBitmap = 0; + if (m_hOldPen) { // ::SelectObject((HDC) dc, (HPEN) m_oldPen); } - m_oldPen = 0; - if (m_oldBrush) + m_hOldPen = 0; + if (m_hOldBrush) { // ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); } - m_oldBrush = 0; - if (m_oldFont) + m_hOldBrush = 0; + if (m_hOldFont) { // ::SelectObject((HDC) dc, (HFONT) m_oldFont); } - m_oldFont = 0; - if (m_oldPalette) + m_hOldFont = 0; + if (m_hOldPalette) { // ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); } - m_oldPalette = 0; + m_hOldPalette = 0; } - m_brush = wxNullBrush; - m_pen = wxNullPen; - m_palette = wxNullPalette; - m_font = wxNullFont; + m_brush = wxNullBrush; + m_pen = wxNullPen; + m_palette = wxNullPalette; + m_font = wxNullFont; m_backgroundBrush = wxNullBrush; - m_selectedBitmap = wxNullBitmap; + m_vSelectedBitmap = wxNullBitmap; } // --------------------------------------------------------------------------- // clipping // --------------------------------------------------------------------------- -void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) -{ - // TODO +#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( long x, long y - ,long width, long height +void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y + ,wxCoord width, wxCoord height ) { // TODO } -void wxDC::DoClipping(WXHDC dc) +void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) { - if (m_clipping && dc) - { -// TODO: -// IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1), -// XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); - } + // TODO } void wxDC::DestroyClippingRegion(void) @@ -182,8 +194,8 @@ void wxDC::Clear() // TODO } -void wxDC::DoFloodFill( long x - ,long y +void wxDC::DoFloodFill( wxCoord x + ,wxCoord y ,const wxColour& col ,int style ) @@ -191,37 +203,43 @@ void wxDC::DoFloodFill( long x // TODO } -bool wxDC::DoGetPixel(long x, long y, wxColour *col) const +bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const { // TODO return(TRUE); } -void wxDC::DoCrossHair(long x, long y) +void wxDC::DoCrossHair(wxCoord x, wxCoord y) { // TODO } -void wxDC::DoDrawLine(long x1, long y1, long x2, long y2) +void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) { // TODO } -void wxDC::DoDrawArc( long x1, long y1 - ,long x2, long y2 - ,long xc, long yc +void wxDC::DoDrawArc( wxCoord x1, wxCoord y1 + ,wxCoord x2, wxCoord y2 + ,wxCoord xc, wxCoord yc ) { // TODO } -void wxDC::DoDrawPoint(long x, long y) +void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, + wxCoord width, wxCoord height) +{ + // TODO +} + +void wxDC::DoDrawPoint(wxCoord x, wxCoord y) { // TODO } void wxDC::DoDrawPolygon(int n, wxPoint points[] - ,long xoffset, long yoffset + ,wxCoord xoffset, wxCoord yoffset ,int fillStyle ) { @@ -229,34 +247,34 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[] } void wxDC::DoDrawLines( int n, wxPoint points[] - ,long xoffset, long yoffset + ,wxCoord xoffset, wxCoord yoffset ) { // TODO } -void wxDC::DoDrawRectangle(long x, long y, long width, long height) +void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { // TODO } -void wxDC::DoDrawRoundedRectangle( long x, long y - ,long width, long height +void wxDC::DoDrawRoundedRectangle( wxCoord x, wxCoord y + ,wxCoord width, wxCoord height ,double radius ) { // TODO } -void wxDC::DoDrawEllipse(long x, long y, long width, long height) +void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { // TODO } -void wxDC::DoDrawEllipticArc( long x - ,long y - ,long w - ,long h +void wxDC::DoDrawEllipticArc( wxCoord x + ,wxCoord y + ,wxCoord w + ,wxCoord h ,double sa ,double ea ) @@ -264,24 +282,85 @@ void wxDC::DoDrawEllipticArc( long x // TODO } -void wxDC::DoDrawIcon(const wxIcon& icon, long x, long y) +void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) { // TODO } void wxDC::DoDrawBitmap( const wxBitmap &bmp - ,long x, long y + ,wxCoord x, wxCoord y ,bool useMask ) { // TODO } -void wxDC::DoDrawText(const wxString& text, long x, long y) +void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) { // TODO } +void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) +{ + // TODO +} + +void wxDC::DoDrawRotatedText(const wxString& text, + wxCoord x, wxCoord y, + double angle) +{ + // TODO: + /* + if ( angle == 0.0 ) + { + DoDrawText(text, x, y); + } + else + { + LOGFONT lf; + wxFillLogFont(&lf, &m_font); + + // GDI wants the angle in tenth of degree + long angle10 = (long)(angle * 10); + lf.lfEscapement = angle10; + lf. lfOrientation = angle10; + + HFONT hfont = ::CreateFontIndirect(&lf); + if ( !hfont ) + { + wxLogLastError("CreateFont"); + } + else + { + HFONT hfontOld = ::SelectObject(GetHdc(), hfont); + + DrawAnyText(text, x, y); + + (void)::SelectObject(GetHdc(), hfontOld); + } + + // call the bounding box by adding all four vertices of the rectangle + // containing the text to it (simpler and probably not slower than + // determining which of them is really topmost/leftmost/...) + wxCoord w, h; + GetTextExtent(text, &w, &h); + + double rad = DegToRad(angle); + + // "upper left" and "upper right" + CalcBoundingBox(x, y); + CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); + CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); + + // "bottom left" and "bottom right" + x += (wxCoord)(h*sin(rad)); + y += (wxCoord)(h*cos(rad)); + CalcBoundingBox(x, y); + CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); + } +*/ +} + // --------------------------------------------------------------------------- // set GDI objects // --------------------------------------------------------------------------- @@ -291,9 +370,39 @@ void wxDC::SetPalette(const wxPalette& palette) // TODO } -void wxDC::SetFont(const wxFont& font) +void wxDC::SetFont( + const wxFont& rFont +) { - // TODO + // + // Set the old object temporarily, in case the assignment deletes an object + // that's not yet selected out. + // + 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()) + { + HFONT hFont = (HFONT)0; //::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle()); + if (hFont == (HFONT) NULL) + { + wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont.")); + } + if (!m_hOldFont) + m_hOldFont = (WXHFONT) hFont; + } } void wxDC::SetPen(const wxPen& pen) @@ -374,25 +483,25 @@ void wxDC::EndPage() // text metrics // --------------------------------------------------------------------------- -long wxDC::GetCharHeight() const +wxCoord wxDC::GetCharHeight() const { // TODO return(1); } -long wxDC::GetCharWidth() const +wxCoord wxDC::GetCharWidth() const { // TODO return(1); } -void wxDC::GetTextExtent( const wxString& string - ,long* x - ,long* y - ,long* decent - ,long* externalLeading - ,wxFont* theFont - ) const +void wxDC::DoGetTextExtent( const wxString& string + ,wxCoord* x + ,wxCoord* y + ,wxCoord* decent + ,wxCoord* externalLeading + ,wxFont* theFont + ) const { // TODO: } @@ -426,12 +535,12 @@ void wxDC::SetSystemScale(double x, double y) SetMapMode(m_mappingMode); } -void wxDC::SetLogicalOrigin( long x, long y ) +void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) { // TODO: }; -void wxDC::SetDeviceOrigin( long x, long y ) +void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) { // TODO: }; @@ -440,85 +549,57 @@ void wxDC::SetDeviceOrigin( long x, long y ) // coordinates transformations // --------------------------------------------------------------------------- -long wxDCBase::DeviceToLogicalX(long x) const +wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const { - long new_x = x - m_deviceOriginX; - if (new_x > 0) - return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; - else - return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; -}; + return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); +} -long wxDCBase::DeviceToLogicalXRel(long x) const +wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const { - if (x > 0) - return (long)((double)(x) / m_scaleX + 0.5); - else - return (long)((double)(x) / m_scaleX - 0.5); -}; + return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX)); +} -long wxDCBase::DeviceToLogicalY(long y) const +wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const { - long new_y = y - m_deviceOriginY; - if (new_y > 0) - return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; - else - return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; -}; + return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); +} -long wxDCBase::DeviceToLogicalYRel(long y) const +wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const { - if (y > 0) - return (long)((double)(y) / m_scaleY + 0.5); - else - return (long)((double)(y) / m_scaleY - 0.5); -}; + return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY)); +} -long wxDCBase::LogicalToDeviceX(long x) const +wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const { - long new_x = x - m_logicalOriginX; - if (new_x > 0) - return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; - else - return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; -}; + return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); +} -long wxDCBase::LogicalToDeviceXRel(long x) const +wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const { - if (x > 0) - return (long)((double)(x) * m_scaleX + 0.5); - else - return (long)((double)(x) * m_scaleX - 0.5); -}; + return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX); +} -long wxDCBase::LogicalToDeviceY(long y) const +wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const { - long new_y = y - m_logicalOriginY; - if (new_y > 0) - return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; - else - return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; -}; + return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); +} -long wxDCBase::LogicalToDeviceYRel(long y) const +wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const { - if (y > 0) - return (long)((double)(y) * m_scaleY + 0.5); - else - return (long)((double)(y) * m_scaleY - 0.5); -}; + return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY); +} // --------------------------------------------------------------------------- // bit blit // --------------------------------------------------------------------------- -bool wxDC::DoBlit( long xdest - ,long ydest - ,long width - ,long height +bool wxDC::DoBlit( wxCoord xdest + ,wxCoord ydest + ,wxCoord width + ,wxCoord height ,wxDC *source - ,long xsrc - ,long ysrc + ,wxCoord xsrc + ,wxCoord ysrc ,int rop ,bool useMask ) @@ -555,7 +636,7 @@ void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, float *descent, float *externalLeading, wxFont *theFont, bool use16bit) const { - long x1, y1, descent1, externalLeading1; + wxCoord x1, y1, descent1, externalLeading1; GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); *x = x1; *y = y1; if (descent)