X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7cdc2f1e4263b8069921c023a780e7feb05816c5..bada28f00f12666ef31f0543cea2cde86b7935c7:/src/os2/dc.cpp diff --git a/src/os2/dc.cpp b/src/os2/dc.cpp index 14f009b007..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,52 +89,59 @@ 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( wxCoord x, wxCoord y @@ -134,14 +151,9 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y // 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) @@ -215,6 +227,12 @@ void wxDC::DoDrawArc( wxCoord x1, wxCoord y1 // TODO } +void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1, + wxCoord width, wxCoord height) +{ + // TODO +} + void wxDC::DoDrawPoint(wxCoord x, wxCoord y) { // TODO @@ -282,6 +300,67 @@ 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) @@ -442,71 +551,43 @@ void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const { - wxCoord new_x = x - m_deviceOriginX; - if (new_x > 0) - return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; - else - return (wxCoord)((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); +} wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const { - if (x > 0) - return (wxCoord)((double)(x) / m_scaleX + 0.5); - else - return (wxCoord)((double)(x) / m_scaleX - 0.5); -}; + return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX)); +} wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const { - wxCoord new_y = y - m_deviceOriginY; - if (new_y > 0) - return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; - else - return (wxCoord)((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); +} wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const { - if (y > 0) - return (wxCoord)((double)(y) / m_scaleY + 0.5); - else - return (wxCoord)((double)(y) / m_scaleY - 0.5); -}; + return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY)); +} wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const { - wxCoord new_x = x - m_logicalOriginX; - if (new_x > 0) - return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; - else - return (wxCoord)((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); +} wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const { - if (x > 0) - return (wxCoord)((double)(x) * m_scaleX + 0.5); - else - return (wxCoord)((double)(x) * m_scaleX - 0.5); -}; + return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX); +} wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const { - wxCoord new_y = y - m_logicalOriginY; - if (new_y > 0) - return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; - else - return (wxCoord)((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); +} wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const { - if (y > 0) - return (wxCoord)((double)(y) * m_scaleY + 0.5); - else - return (wxCoord)((double)(y) * m_scaleY - 0.5); -}; + return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY); +} // --------------------------------------------------------------------------- // bit blit