+ 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
+// ---------------------------------------------------------------------------
+
+void wxDC::SetPalette(
+ const wxPalette& rPalette
+)
+{
+ if (m_hOldFont)
+ {
+ m_hOldFont = 0;
+ }
+ m_palette = rPalette;
+ if (!rPalette.Ok())
+ {
+ if (m_hOldFont)
+ {
+ m_hOldFont = 0;
+ }
+ }
+ HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
+ if (!m_hOldPalette)
+ m_hOldPalette = (WXHPALETTE)hOldPal;
+} // end of wxDC::SetPalette
+
+void wxDC::SetFont(
+ const wxFont& rFont
+)
+{
+ //
+ // Set the old object temporarily, in case the assignment deletes an object
+ // that's not yet selected out.
+ //
+ if (m_hOldFont)
+ {
+ m_hOldFont = 0;
+ }
+ m_font = rFont;
+ if (!rFont.Ok())
+ {
+ m_hOldFont = 0;
+ }
+
+ m_font.SetPS(m_hPS); // this will realize the font
+
+ if (m_font.Ok())
+ {
+ HFONT hFont = m_font.GetResourceHandle();
+ if (hFont == (HFONT) NULL)
+ {
+ wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
+ }
+ if (!m_hOldFont)
+ m_hOldFont = (WXHFONT) hFont;
+ }
+} // end of wxDC::SetFont
+
+void wxDC::SetPen(
+ const wxPen& rPen
+)
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_pen == rPen)
+ return;
+ m_pen = rPen;
+ if (!m_pen.Ok())
+ return;
+
+ if (m_hOldPen)
+ m_hOldPen = 0L;
+ m_pen = rPen;
+
+ if (!m_pen.Ok())
+ {
+ if (m_hOldPen)
+ {
+ m_pen.SetPS((HPS)m_hOldPen);
+ }
+ m_hOldPen = 0L;
+ }
+
+ if (m_pen.Ok())
+ {
+ if (m_pen.GetResourceHandle())
+ {
+ m_pen.SetPS(m_hPS);
+ if (!m_hOldPen)
+ m_hOldPen = m_pen.GetPS();
+ }
+ }
+}
+
+void wxDC::SetBrush(
+ const wxBrush& rBrush
+)
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (m_hOldBrush)
+ m_hOldBrush = 0L;
+ m_brush = rBrush;
+ if (!m_brush.Ok())
+ if (m_brush == rBrush)
+ return;
+ if (!m_brush.Ok())
+ if (m_hOldBrush)
+ m_hOldBrush = 0L;
+
+ 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 = (WXHWND)m_brush.GetPS();
+ }
+ }
+} // end of wxDC::SetBrush
+
+void wxDC::SetBackground(
+ const wxBrush& rBrush
+)
+{
+ m_backgroundBrush = rBrush;
+ if (!m_backgroundBrush.Ok())
+ return;
+ if (m_pCanvas)
+ {
+ bool bCustomColours = TRUE;
+
+ //
+ // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
+ // change background colours from the control-panel specified colours.
+ //
+ if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
+ ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
+ bCustomColours = FALSE;
+ if (bCustomColours)
+ {
+ if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
+ {
+ m_pCanvas->SetTransparent(TRUE);
+ }
+ else
+ {
+ //
+ // Setting the background brush of a DC
+ // doesn't affect the window background colour. However,
+ // I'm leaving in the transparency setting because it's needed by
+ // various controls (e.g. wxStaticText) to determine whether to draw
+ // transparently or not. TODO: maybe this should be a new function
+ // wxWindow::SetTransparency(). Should that apply to the child itself, or the
+ // parent?
+ // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
+ //
+ m_pCanvas->SetTransparent(FALSE);
+ }
+ }
+ }
+ COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
+ (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
+} // end of wxDC::SetBackground
+
+void wxDC::SetBackgroundMode(
+ int nMode
+)
+{
+ m_backgroundMode = nMode;
+} // end of wxDC::SetBackgroundMode
+
+void wxDC::SetLogicalFunction(
+ int nFunction
+)
+{
+ m_logicalFunction = nFunction;
+ SetRop((WXHDC)m_hDC);
+} // wxDC::SetLogicalFunction
+
+void wxDC::SetRop(
+ WXHDC hDC
+)
+{
+ if (!hDC || m_logicalFunction < 0)
+ return;
+
+ LONG lCRop;
+ switch (m_logicalFunction)
+ {
+ case wxXOR:
+ lCRop = FM_XOR;
+ break;
+
+ case wxINVERT:
+ lCRop = FM_INVERT;
+ break;
+
+ case wxOR_REVERSE:
+ lCRop = FM_MERGESRCNOT;
+ break;
+
+ case wxAND_REVERSE:
+ lCRop = FM_NOTMASKSRC;
+ break;
+
+ case wxCLEAR:
+ lCRop = FM_ONE;
+ break;
+
+ case wxSET:
+ lCRop = FM_ZERO;
+ break;
+
+ case wxSRC_INVERT:
+ lCRop = FM_MERGENOTSRC;
+ break;
+
+ case wxOR_INVERT:
+ lCRop = FM_MERGESRCNOT;
+ break;
+
+ case wxAND:
+ lCRop = FM_AND;
+ break;
+
+ case wxOR:
+ lCRop = FM_OR;
+ break;
+
+ case wxAND_INVERT:
+ lCRop = FM_SUBTRACT;
+ break;
+
+ case wxEQUIV:
+ case wxNAND:
+ case wxCOPY:
+ default:
+ lCRop = FM_OVERPAINT;
+ break;
+ }
+ ::GpiSetMix((HPS)hDC, lCRop);
+} // end of wxDC::SetRop
+
+bool wxDC::StartDoc(
+ const wxString& rsMessage
+)
+{
+ // We might be previewing, so return TRUE to let it continue.
+ return TRUE;
+} // end of wxDC::StartDoc
+
+void wxDC::EndDoc()
+{
+} // end of wxDC::EndDoc
+
+void wxDC::StartPage()
+{
+} // end of wxDC::StartPage
+
+void wxDC::EndPage()
+{
+} // end of wxDC::EndPage
+
+// ---------------------------------------------------------------------------
+// text metrics
+// ---------------------------------------------------------------------------
+
+wxCoord wxDC::GetCharHeight() const
+{
+ FONTMETRICS vFM; // metrics structure
+
+ ::GpiQueryFontMetrics( m_hPS
+ ,sizeof(FONTMETRICS)
+ ,&vFM
+ );
+ return YDEV2LOGREL(vFM.lXHeight);
+}
+
+wxCoord wxDC::GetCharWidth() const
+{
+ FONTMETRICS vFM; // metrics structure
+
+ ::GpiQueryFontMetrics( m_hPS
+ ,sizeof(FONTMETRICS)
+ ,&vFM
+ );
+ return XDEV2LOGREL(vFM.lAveCharWidth);
+}
+
+void wxDC::DoGetTextExtent(
+ const wxString& rsString
+, wxCoord* pvX
+, wxCoord* pvY
+, wxCoord* pvDescent
+, wxCoord* pvExternalLeading
+, wxFont* pTheFont
+) const
+{
+ POINTL avPoint[TXTBOX_COUNT];
+ POINTL vPtMin;
+ POINTL vPtMax;
+ int i;
+ int l;
+ FONTMETRICS vFM; // metrics structure
+ BOOL bRc;
+ char* pStr;
+ ERRORID vErrorCode; // last error id code
+ wxFont* pFontToUse = (wxFont*)pTheFont;
+
+ char zMsg[128]; // DEBUG
+ wxString sError;
+
+ if (!pFontToUse)
+ pFontToUse = (wxFont*)&m_font;
+ l = rsString.length();
+ pStr = (PCH) rsString.c_str();
+
+ //
+ // In world coordinates.
+ //
+ bRc = ::GpiQueryTextBox( m_hPS
+ ,l
+ ,pStr
+ ,TXTBOX_COUNT // return maximum information
+ ,avPoint // array of coordinates points
+ );
+ if(!bRc)
+ {
+ vErrorCode = ::WinGetLastError(wxGetInstance());
+ sError = wxPMErrorToStr(vErrorCode);
+ // DEBUG
+ sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str());
+ (void)wxMessageBox( "wxWindows Menu sample"
+ ,zMsg
+ ,wxICON_INFORMATION
+ );
+ }
+
+ vPtMin.x = avPoint[0].x;
+ vPtMax.x = avPoint[0].x;
+ vPtMin.y = avPoint[0].y;
+ vPtMax.y = avPoint[0].y;
+ for (i = 1; i < 4; i++)
+ {
+ if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
+ if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
+ if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
+ if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
+ }
+ ::GpiQueryFontMetrics( m_hPS
+ ,sizeof(FONTMETRICS)
+ ,&vFM
+ );
+
+ if (pvX)
+ *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
+ if (pvY)
+ *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
+ if (pvDescent)
+ *pvDescent = vFM.lMaxDescender;
+ if (pvExternalLeading)
+ *pvExternalLeading = vFM.lExternalLeading;
+}
+
+void wxDC::SetMapMode(
+ int nMode
+)
+{
+ int nPixelWidth = 0;
+ int nPixelHeight = 0;
+ int nMmWidth = 1;
+ int nMmHeight = 1;
+ LONG lArray[CAPS_VERTICAL_RESOLUTION];
+
+ m_mappingMode = nMode;
+
+ if(::DevQueryCaps( m_hDC
+ ,CAPS_FAMILY
+ ,CAPS_VERTICAL_RESOLUTION
+ ,lArray
+ ))
+ {
+ LONG lHorzRes;
+ LONG lVertRes;
+
+ nPixelWidth = lArray[CAPS_WIDTH];
+ nPixelHeight = lArray[CAPS_HEIGHT];
+ lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
+ lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
+ nMmWidth = (lHorzRes/1000) * nPixelWidth;
+ nMmWidth = (lVertRes/1000) * nPixelHeight;
+ }
+ if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
+ {
+ return;
+ }
+
+ double dMm2pixelsX = nPixelWidth/nMmWidth;
+ double dMm2pixelsY = nPixelHeight/nMmHeight;
+
+ switch (nMode)
+ {
+ case wxMM_TWIPS:
+ m_logicalScaleX = (twips2mm * dMm2pixelsX);
+ m_logicalScaleY = (twips2mm * dMm2pixelsY);
+ break;
+
+ case wxMM_POINTS:
+ m_logicalScaleX = (pt2mm * dMm2pixelsX);
+ m_logicalScaleY = (pt2mm * dMm2pixelsY);
+ break;
+
+ case wxMM_METRIC:
+ m_logicalScaleX = dMm2pixelsX;
+ m_logicalScaleY = dMm2pixelsY;
+ break;
+
+ case wxMM_LOMETRIC:
+ m_logicalScaleX = (dMm2pixelsX/10.0);
+ m_logicalScaleY = (dMm2pixelsY/10.0);
+ break;
+
+ case wxMM_TEXT:
+ default:
+ m_logicalScaleX = 1.0;
+ m_logicalScaleY = 1.0;
+ break;
+ }
+ SIZEL vSize;
+ ULONG ulOptions;
+
+ ulOptions = ::GpiQueryPS(m_hPS, &vSize);
+ if (!ulOptions & PU_ARBITRARY)
+ {
+ ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
+ ::GpiSetPS(m_hPS, &vSize, ulOptions);
+ }
+ m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
+ m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
+ // ????
+}; // end of wxDC::SetMapMode
+
+void wxDC::SetUserScale(
+ double dX
+, double dY
+)
+{
+ m_userScaleX = dX;
+ m_userScaleY = dY;
+
+ SetMapMode(m_mappingMode);
+} // end of wxDC::SetUserScale
+
+void wxDC::SetAxisOrientation(
+ bool bXLeftRight
+, bool bYBottomUp
+)
+{
+ m_signX = bXLeftRight ? 1 : -1;
+ m_signY = bYBottomUp ? -1 : 1;
+
+ SetMapMode(m_mappingMode);
+} // end of wxDC::SetAxisOrientation
+
+void wxDC::SetSystemScale(
+ double dX
+, double dY
+)
+{
+ m_scaleX = dX;
+ m_scaleY = dY;
+
+ SetMapMode(m_mappingMode);
+} // end of wxDC::SetSystemScale
+
+void wxDC::SetLogicalOrigin(
+ wxCoord vX
+, wxCoord vY
+)
+{
+ RECTL vRect;
+
+ ::GpiQueryPageViewport( m_hPS
+ ,&vRect
+ );
+ vRect.xRight -= vX;
+ vRect.yTop += vY;
+ vRect.xLeft = vX;
+ vRect.yBottom = vY;
+ ::GpiSetPageViewport( m_hPS
+ ,&vRect
+ );
+}; // end of wxDC::SetLogicalOrigin
+
+void wxDC::SetDeviceOrigin(
+ wxCoord vX
+, wxCoord vY
+)
+{
+ RECTL vRect;
+
+ m_deviceOriginX = vX;
+ m_deviceOriginY = vY;
+ ::GpiQueryPageViewport( m_hPS
+ ,&vRect
+ );
+ vRect.xLeft += vX;
+ vRect.xRight += vX;
+ vRect.yBottom -= vY;
+ vRect.yTop -= vY;
+ ::GpiSetPageViewport( m_hPS
+ ,&vRect
+ );
+}; // end of wxDC::SetDeviceOrigin
+
+// ---------------------------------------------------------------------------
+// coordinates transformations
+// ---------------------------------------------------------------------------
+
+wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
+{
+ return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
+}
+
+wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
+{
+ // axis orientation is not taken into account for conversion of a distance
+ return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
+}
+
+wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
+{
+ return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
+}
+
+wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
+{
+ // axis orientation is not taken into account for conversion of a distance
+ return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
+}
+
+wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
+{
+ return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
+}
+
+wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
+{
+ // axis orientation is not taken into account for conversion of a distance
+ return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
+}
+
+wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
+{
+ return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
+}
+
+wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
+{
+ // axis orientation is not taken into account for conversion of a distance
+ return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
+}
+
+// ---------------------------------------------------------------------------
+// bit blit
+// ---------------------------------------------------------------------------
+
+bool wxDC::DoBlit(
+ wxCoord vXdest
+, wxCoord vYdest
+, wxCoord vWidth
+, wxCoord vHeight
+, wxDC* pSource
+, wxCoord vXsrc
+, wxCoord vYsrc
+, int nRop
+, bool bUseMask
+, wxCoord vXsrcMask
+, wxCoord vYsrcMask
+)
+{
+ wxMask* pMask = NULL;
+ CHARBUNDLE vCbnd;
+ COLORREF vOldTextColor;
+ COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
+
+ if (bUseMask)
+ {
+ const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
+
+ pMask = rBmp.GetMask();
+ if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
+ {
+ bUseMask = FALSE;
+ }
+ }
+
+ ::GpiQueryAttrs( m_hPS
+ ,PRIM_CHAR
+ ,CBB_COLOR
+ ,&vCbnd
+ );
+ vOldTextColor = (COLORREF)vCbnd.lColor;
+
+ if (m_textForegroundColour.Ok())
+ {
+ vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
+ ::GpiSetAttrs( m_hPS // presentation-space handle
+ ,PRIM_CHAR // Char primitive.
+ ,CBB_COLOR // sets color.
+ ,0
+ ,&vCbnd // buffer for attributes.
+ );
+ }
+ if (m_textBackgroundColour.Ok())
+ {
+ ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
+ }
+
+ LONG lRop = ROP_SRCCOPY;
+
+ switch (nRop)
+ {
+ case wxXOR: lRop = ROP_SRCINVERT; break;
+ case wxINVERT: lRop = ROP_DSTINVERT; break;
+ case wxOR_REVERSE: lRop = 0x00DD0228; break;
+ case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
+ case wxCLEAR: lRop = ROP_ZERO; break;
+ case wxSET: lRop = ROP_ONE; break;
+ case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
+ case wxAND: lRop = ROP_SRCAND; break;
+ case wxOR: lRop = ROP_SRCPAINT; break;
+ case wxEQUIV: lRop = 0x00990066; break;
+ case wxNAND: lRop = 0x007700E6; break;
+ case wxAND_INVERT: lRop = 0x00220326; break;
+ case wxCOPY: lRop = ROP_SRCCOPY; break;
+ case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
+ case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
+ case wxNOR: lRop = ROP_NOTSRCCOPY; break;
+ default:
+ wxFAIL_MSG( wxT("unsupported logical function") );
+ return FALSE;
+ }
+
+ bool bSuccess;
+
+ if (bUseMask)
+ {
+ //
+ // Blit bitmap with mask
+ //
+
+ //
+ // Create a temp buffer bitmap and DCs/PSs to access it and the mask
+ //
+ HDC hDCMask;
+ HDC hDCBuffer;
+ HPS hPSMask;
+ HPS hPSBuffer;
+ DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
+ BITMAPINFOHEADER2 vBmpHdr;
+ HBITMAP hBufBitmap;
+ SIZEL vSize = {0, 0};
+ LONG rc;
+
+ memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
+ vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
+ vBmpHdr.cx = vWidth;
+ vBmpHdr.cy = vHeight;
+ vBmpHdr.cPlanes = 1;
+ vBmpHdr.cBitCount = 24;
+
+#if wxUSE_DC_CACHEING
+ if (TRUE)
+ {
+ //
+ // create a temp buffer bitmap and DCs to access it and the mask
+ //
+ wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
+ ,pSource->GetHPS()
+ );
+ wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
+ ,GetHPS()
+ );
+ wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
+ ,vWidth
+ ,vHeight
+ );
+
+ hPSMask = pDCCacheEntry1->m_hPS;
+ hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
+ hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
+ }
+ else
+#endif
+ {
+ hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
+ hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
+ hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
+ hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
+ hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
+ }
+
+ POINTL aPoint1[4] = { 0, 0
+ ,vWidth, vHeight
+ ,vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ };
+ POINTL aPoint2[4] = { 0, 0
+ ,vWidth, vHeight
+ ,vXsrc, vYsrc
+ ,vXsrc + vWidth, vYsrc + vHeight
+ };
+ POINTL aPoint3[4] = { vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ ,vXsrc, vYsrc
+ ,vXsrc + vWidth, vYsrc + vHeight
+ };
+ POINTL aPoint4[4] = { vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ ,0, 0
+ ,vWidth, vHeight
+ };
+ ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
+ ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
+
+ //
+ // Copy dest to buffer
+ //
+ rc = ::GpiBitBlt( hPSBuffer
+ ,GetHPS()
+ ,4L
+ ,aPoint1
+ ,ROP_SRCCOPY
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Copy src to buffer using selected raster op
+ //
+ rc = ::GpiBitBlt( hPSBuffer
+ ,GetHPS()
+ ,4L
+ ,aPoint2
+ ,lRop
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Set masked area in buffer to BLACK (pixel value 0)
+ //
+ COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
+ COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
+
+ ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
+ ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
+
+ rc = ::GpiBitBlt( hPSBuffer
+ ,hPSMask
+ ,4L
+ ,aPoint2
+ ,ROP_SRCAND
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Set unmasked area in dest to BLACK
+ //
+ ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
+ ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
+ rc = ::GpiBitBlt( GetHPS()
+ ,hPSMask
+ ,4L
+ ,aPoint3
+ ,ROP_SRCAND
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Restore colours to original values
+ //
+ ::GpiSetBackColor(GetHPS(), vPrevBkCol);
+ ::GpiSetColor(GetHPS(), vPrevCol);
+
+ //
+ // OR buffer to dest
+ //
+ rc = ::GpiBitBlt( GetHPS()
+ ,hPSMask
+ ,4L
+ ,aPoint4
+ ,ROP_SRCPAINT
+ ,BBO_IGNORE
+ );
+ if (rc == GPI_ERROR)
+ {
+ bSuccess = FALSE;
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ //
+ // Tidy up temporary DCs and bitmap
+ //
+ ::GpiSetBitmap(hPSMask, NULLHANDLE);
+ ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
+#if !wxUSE_DC_CACHEING
+ ::GpiDestroyPS(hPSMask);
+ ::GpiDestroyPS(hPSBuffer);
+ ::DevCloseDC(hDCMask);
+ ::DevCloseDC(hDCBuffer);
+ ::GpiDeleteBitmap(hBufBitmap);
+#endif
+ bSuccess = TRUE;
+ }
+ else // no mask, just BitBlt() it
+ {
+ POINTL aPoint[4] = { vXdest, vYdest
+ ,vXdest + vWidth, vYdest + vHeight
+ ,vXsrc, vYsrc
+ ,vXsrc + vWidth, vYsrc + vHeight
+ };
+
+ bSuccess = (::GpiBitBlt( m_hPS
+ ,pSource->GetHPS()
+ ,4L
+ ,aPoint
+ ,lRop
+ ,BBO_IGNORE
+ ) != GPI_ERROR);
+ if (!bSuccess )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+ }
+ vCbnd.lColor = (LONG)vOldTextColor;
+ ::GpiSetAttrs( m_hPS // presentation-space handle
+ ,PRIM_CHAR // Char primitive.
+ ,CBB_COLOR // sets color.
+ ,0
+ ,&vCbnd // buffer for attributes.
+ );
+ ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
+ return bSuccess;
+}
+
+void wxDC::DoGetSize(
+ int* pnWidth
+, int* pnHeight
+) const
+{
+ LONG lArray[CAPS_HEIGHT];
+
+ if(::DevQueryCaps( m_hDC
+ ,CAPS_FAMILY
+ ,CAPS_HEIGHT
+ ,lArray
+ ))
+ {
+ *pnWidth = lArray[CAPS_WIDTH];
+ *pnHeight = lArray[CAPS_HEIGHT];
+ }
+}; // end of wxDC::DoGetSize(
+
+void wxDC::DoGetSizeMM(
+ int* pnWidth
+, int* pnHeight
+) const
+{
+ LONG lArray[CAPS_VERTICAL_RESOLUTION];
+
+ if(::DevQueryCaps( m_hDC
+ ,CAPS_FAMILY
+ ,CAPS_VERTICAL_RESOLUTION
+ ,lArray
+ ))
+ {
+ int nWidth;
+ int nHeight;
+ int nHorzRes;
+ int nVertRes;
+
+ nWidth = lArray[CAPS_WIDTH];
+ nHeight = lArray[CAPS_HEIGHT];
+ nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
+ nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
+ nWidth = (nHorzRes/1000) * nWidth;
+ nHeight = (nVertRes/1000) * nHeight;
+ }
+}; // end of wxDC::DoGetSizeMM
+
+wxSize wxDC::GetPPI() const
+{
+ LONG lArray[CAPS_VERTICAL_RESOLUTION];
+ int nWidth;
+ int nHeight;
+
+ if(::DevQueryCaps( m_hDC
+ ,CAPS_FAMILY
+ ,CAPS_VERTICAL_RESOLUTION
+ ,lArray
+ ))
+ {
+ int nPelWidth;
+ int nPelHeight;
+ int nHorzRes;
+ int nVertRes;
+
+ nPelWidth = lArray[CAPS_WIDTH];
+ nPelHeight = lArray[CAPS_HEIGHT];
+ nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
+ nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
+ nWidth = (nHorzRes/39.3) * nPelWidth;
+ nHeight = (nVertRes/39.3) * nPelHeight;
+ }
+ return (wxSize(nWidth,nHeight));
+} // end of wxDC::GetPPI
+
+void wxDC::SetLogicalScale(
+ double dX
+, double dY
+)
+{
+ m_logicalScaleX = dX;
+ m_logicalScaleY = dY;
+}; // end of wxDC::SetLogicalScale
+
+#if WXWIN_COMPATIBILITY
+void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
+ float *descent, float *externalLeading,
+ wxFont *theFont, bool use16bit) const
+{
+ wxCoord x1, y1, descent1, externalLeading1;
+ GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
+ *x = x1; *y = y1;
+ if (descent)
+ *descent = descent1;
+ if (externalLeading)
+ *externalLeading = externalLeading1;
+}
+#endif