#include "wx/icon.h"
#endif
+#include "wx/sysopt.h"
#include "wx/dcprint.h"
+#include "wx/module.h"
#include <string.h>
#include <math.h>
m_oldPen = 0;
m_oldBrush = 0;
m_oldFont = 0;
+#if wxUSE_PALETTE
m_oldPalette = 0;
+#endif // wxUSE_PALETTE
m_bOwnsDC = FALSE;
m_hDC = 0;
::SelectObject((HDC) dc, (HFONT) m_oldFont);
}
m_oldFont = 0;
+
+#if wxUSE_PALETTE
if (m_oldPalette)
{
::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE);
}
m_oldPalette = 0;
+#endif // wxUSE_PALETTE
}
m_brush = wxNullBrush;
m_pen = wxNullPen;
+#if wxUSE_PALETTE
m_palette = wxNullPalette;
+#endif // wxUSE_PALETTE
m_font = wxNullFont;
m_backgroundBrush = wxNullBrush;
m_selectedBitmap = wxNullBitmap;
// 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::UpdateClipBox()
+{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
+ 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 cx, wxCoord cy, wxCoord cw, wxCoord ch)
+void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_clipping = TRUE;
- IntersectClipRect(GetHdc(), XLOG2DEV(cx), YLOG2DEV(cy),
- XLOG2DEV(cx + cw), YLOG2DEV(cy + ch));
- DO_SET_CLIPPING_BOX()
+
+ // the region coords are always the device ones, so do the translation
+ // manually
+ //
+ // FIXME: possible +/-1 error here, to check!
+ HRGN hrgn = ::CreateRectRgn(LogicalToDeviceX(x),
+ LogicalToDeviceY(y),
+ LogicalToDeviceX(x + w),
+ LogicalToDeviceY(y + h));
+ if ( !hrgn )
+ {
+ wxLogLastError(_T("CreateRectRgn"));
+ }
+ else
+ {
+ if ( ::SelectClipRgn(GetHdc(), hrgn) == ERROR )
+ {
+ wxLogLastError(_T("SelectClipRgn"));
+ }
+ DeleteObject(hrgn);
+
+ UpdateClipBox();
+ }
}
void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
{
- wxCHECK_RET( region.GetHRGN(), wxT("invalid clipping region") );
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
+ wxCHECK_RET( GetHrgnOf(region), wxT("invalid clipping region") );
m_clipping = TRUE;
#ifdef __WIN16__
- SelectClipRgn(GetHdc(), (HRGN) region.GetHRGN());
-#else
- ExtSelectClipRgn(GetHdc(), (HRGN) region.GetHRGN(), RGN_AND);
-#endif
+ SelectClipRgn(GetHdc(), GetHrgnOf(region));
+#else // Win32
+ ExtSelectClipRgn(GetHdc(), GetHrgnOf(region), RGN_AND);
+#endif // Win16/32
- DO_SET_CLIPPING_BOX()
+ UpdateClipBox();
}
void wxDC::DestroyClippingRegion()
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
if (m_clipping && m_hDC)
{
// TODO: this should restore the previous clipping region,
SelectClipRgn(GetHdc(), rgn);
DeleteObject(rgn);
}
+
m_clipping = FALSE;
}
bool wxDC::CanGetTextExtent() const
{
+#ifdef __WXMICROWIN__
+ // TODO Extend MicroWindows' GetDeviceCaps function
+ return TRUE;
+#else
// What sort of display is it?
int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY);
return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER);
+#endif
}
int wxDC::GetDepth() const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return 16;
+#endif
+
return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL);
}
void wxDC::Clear()
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
RECT rect;
if ( m_canvas )
{
void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
col.GetPixel(),
style == wxFLOOD_SURFACE ? FLOODFILLSURFACE
bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return FALSE;
+#endif
+
wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") );
// get the color of the pixel
void wxDC::DoCrossHair(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxCoord x1 = x-VIEWPORT_EXTENT;
wxCoord y1 = y-VIEWPORT_EXTENT;
wxCoord x2 = x+VIEWPORT_EXTENT;
void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
(void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL);
(void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2));
wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
double dx = xc - x1;
void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1,
wxCoord width, wxCoord height)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxCoord x2 = x1 + width,
y2 = y1 + height;
-#if defined(__WIN32__) && !defined(__SC__)
+#if defined(__WIN32__) && !defined(__SC__) && !defined(__WXMICROWIN__)
RECT rect;
rect.left = x1;
rect.top = y1;
HPEN hBrushOld = (HPEN)::SelectObject(GetHdc(), whiteBrush);
::SetROP2(GetHdc(), R2_COPYPEN);
Rectangle(GetHdc(), x1, y1, x2, y2);
- MoveTo(GetHdc(), x1, y1);
+ MoveToEx(GetHdc(), x1, y1, NULL);
LineTo(GetHdc(), x2, y2);
- MoveTo(GetHdc(), x2, y1);
+ MoveToEx(GetHdc(), x2, y1, NULL);
LineTo(GetHdc(), x1, y2);
::SelectObject(GetHdc(), hPenOld);
::SelectObject(GetHdc(), hBrushOld);
void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
COLORREF color = 0x00ffffff;
if (m_pen.Ok())
{
void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
// Do things less efficiently if we have offsets
void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// Do things less efficiently if we have offsets
if (xoffset != 0 || yoffset != 0)
{
void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
wxCoord x2 = x + width;
void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
// Now, a negative radius value is interpreted to mean
void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
wxCoord x2 = (x+width);
// Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
wxCoord x2 = x + w;
void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxCHECK_RET( icon.Ok(), wxT("invalid icon in DrawIcon") );
#ifdef __WIN32__
void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
int width = bmp.GetWidth(),
if ( useMask )
{
#ifdef __WIN32__
- HDC hdcMem = ::CreateCompatibleDC(GetHdc());
- ::SelectObject(hdcMem, GetHbitmapOf(bmp));
-
// use MaskBlt() with ROP which doesn't do anything to dst in the mask
// points
- bool ok = ::MaskBlt(GetHdc(), x, y, width, height,
+ // On some systems, MaskBlt succeeds yet is much much slower
+ // than the wxWindows fall-back implementation. So we need
+ // to be able to switch this on and off at runtime.
+ bool ok = FALSE;
+#if wxUSE_SYSTEM_OPTIONS
+ if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0)
+#endif
+ {
+ HDC hdcMem = ::CreateCompatibleDC(GetHdc());
+ ::SelectObject(hdcMem, GetHbitmapOf(bmp));
+
+ ok = ::MaskBlt(GetHdc(), x, y, width, height,
hdcMem, 0, 0,
hbmpMask, 0, 0,
MAKEROP4(SRCCOPY, DSTCOPY)) != 0;
- ::DeleteDC(hdcMem);
+ ::DeleteDC(hdcMem);
+ }
if ( !ok )
#endif // Win32
void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
DrawAnyText(text, x, y);
// update the bounding box
void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// prepare for drawing the text
if ( m_textForegroundColour.Ok() )
SetTextColor(GetHdc(), m_textForegroundColour.GetPixel());
wxCoord x, wxCoord y,
double angle)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// we test that we have some font because otherwise we should still use the
// "else" part below to avoid that DrawRotatedText(angle = 180) and
// DrawRotatedText(angle = 0) use different fonts (we can't use the default
{
DoDrawText(text, x, y);
}
+#ifndef __WXMICROWIN__
else
{
- // NB: don't take DEFAULT_GUI_FONT because it's not TrueType and so
- // can't have non zero orientation/escapement
- wxFont font = m_font.Ok() ? m_font : *wxNORMAL_FONT;
+ // NB: don't take DEFAULT_GUI_FONT (a.k.a. wxSYS_DEFAULT_GUI_FONT)
+ // because it's not TrueType and so can't have non zero
+ // orientation/escapement under Win9x
+ wxFont font = m_font.Ok() ? m_font : *wxSWISS_FONT;
HFONT hfont = (HFONT)font.GetResourceHandle();
LOGFONT lf;
if ( ::GetObject(hfont, sizeof(lf), &lf) == 0 )
CalcBoundingBox(x, y);
CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
}
+#endif
}
// ---------------------------------------------------------------------------
// set GDI objects
// ---------------------------------------------------------------------------
+#if wxUSE_PALETTE
+
void wxDC::SetPalette(const wxPalette& palette)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// Set the old object temporarily, in case the assignment deletes an object
// that's not yet selected out.
if (m_oldPalette)
}
}
+#endif // wxUSE_PALETTE
+
void wxDC::SetFont(const wxFont& the_font)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// Set the old object temporarily, in case the assignment deletes an object
// that's not yet selected out.
if (m_oldFont)
void wxDC::SetPen(const wxPen& pen)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// Set the old object temporarily, in case the assignment deletes an object
// that's not yet selected out.
if (m_oldPen)
void wxDC::SetBrush(const wxBrush& brush)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
// Set the old object temporarily, in case the assignment deletes an object
// that's not yet selected out.
if (m_oldBrush)
void wxDC::SetBackground(const wxBrush& brush)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_backgroundBrush = brush;
if (!m_backgroundBrush.Ok())
void wxDC::SetBackgroundMode(int mode)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_backgroundMode = mode;
// SetBackgroundColour now only refers to text background
void wxDC::SetLogicalFunction(int function)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_logicalFunction = function;
SetRop(m_hDC);
wxCoord wxDC::GetCharHeight() const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return 0;
+#endif
+
TEXTMETRIC lpTextMetric;
GetTextMetrics(GetHdc(), &lpTextMetric);
wxCoord wxDC::GetCharWidth() const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return 0;
+#endif
+
TEXTMETRIC lpTextMetric;
GetTextMetrics(GetHdc(), &lpTextMetric);
wxCoord *descent, wxCoord *externalLeading,
wxFont *font) const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC())
+ {
+ if (x) *x = 0;
+ if (y) *y = 0;
+ if (descent) *descent = 0;
+ if (externalLeading) *externalLeading = 0;
+ return;
+ }
+#endif
+
HFONT hfontOld;
if ( font )
{
void wxDC::SetMapMode(int mode)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_mappingMode = mode;
int pixel_width = 0;
void wxDC::SetUserScale(double x, double y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_userScaleX = x;
m_userScaleY = y;
void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_signX = xLeftRight ? 1 : -1;
m_signY = yBottomUp ? -1 : 1;
void wxDC::SetSystemScale(double x, double y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_scaleX = x;
m_scaleY = y;
void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_logicalOriginX = x;
m_logicalOriginY = y;
void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_deviceOriginX = x;
m_deviceOriginY = y;
bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
wxCoord width, wxCoord height,
wxDC *source, wxCoord xsrc, wxCoord ysrc,
- int rop, bool useMask)
+ int rop, bool useMask,
+ wxCoord xsrcMask, wxCoord ysrcMask)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return FALSE;
+#endif
+
wxMask *mask = NULL;
if ( useMask )
{
}
}
+ if (xsrcMask == -1 && ysrcMask == -1)
+ {
+ xsrcMask = xsrc; ysrcMask = ysrc;
+ }
+
COLORREF old_textground = ::GetTextColor(GetHdc());
COLORREF old_background = ::GetBkColor(GetHdc());
if (m_textForegroundColour.Ok())
return FALSE;
}
- bool success;
+ bool success = FALSE;
if (useMask)
{
// transparent, so use "DSTCOPY" ROP for the mask points (the usual
// meaning of fg and bg is inverted which corresponds to wxWin notion
// of the mask which is also contrary to the Windows one)
- success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
+
+ // On some systems, MaskBlt succeeds yet is much much slower
+ // than the wxWindows fall-back implementation. So we need
+ // to be able to switch this on and off at runtime.
+#if wxUSE_SYSTEM_OPTIONS
+ if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0)
+#endif
+ {
+ success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
GetHdcOf(*source), xsrc, ysrc,
- (HBITMAP)mask->GetMaskBitmap(), xsrc, ysrc,
+ (HBITMAP)mask->GetMaskBitmap(), xsrcMask, ysrcMask,
MAKEROP4(dwRop, DSTCOPY)) != 0;
+ }
if ( !success )
#endif // Win32
{
// Blit bitmap with mask
+ HDC dc_mask ;
+ HDC dc_buffer ;
+ HBITMAP buffer_bmap ;
+
+#if wxUSE_DC_CACHEING
+ // create a temp buffer bitmap and DCs to access it and the mask
+ wxDCCacheEntry* dcCacheEntry1 = FindDCInCache(NULL, source->GetHDC());
+ dc_mask = (HDC) dcCacheEntry1->m_dc;
+ wxDCCacheEntry* dcCacheEntry2 = FindDCInCache(dcCacheEntry1, GetHDC());
+ dc_buffer = (HDC) dcCacheEntry2->m_dc;
+
+ wxDCCacheEntry* bitmapCacheEntry = FindBitmapInCache(GetHDC(),
+ width, height);
+
+ buffer_bmap = (HBITMAP) bitmapCacheEntry->m_bitmap;
+#else // !wxUSE_DC_CACHEING
// create a temp buffer bitmap and DCs to access it and the mask
- HDC dc_mask = ::CreateCompatibleDC(GetHdcOf(*source));
- HDC dc_buffer = ::CreateCompatibleDC(GetHdc());
- HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
+ dc_mask = ::CreateCompatibleDC(GetHdcOf(*source));
+ dc_buffer = ::CreateCompatibleDC(GetHdc());
+ buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
+#endif // wxUSE_DC_CACHEING/!wxUSE_DC_CACHEING
::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap());
::SelectObject(dc_buffer, buffer_bmap);
COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255));
COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0));
if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
- dc_mask, xsrc, ysrc, SRCAND) )
+ dc_mask, xsrcMask, ysrcMask, SRCAND) )
{
wxLogLastError(wxT("BitBlt"));
}
::SetBkColor(GetHdc(), RGB(0, 0, 0));
::SetTextColor(GetHdc(), RGB(255, 255, 255));
if ( !::BitBlt(GetHdc(), xdest, ydest, (int)width, (int)height,
- dc_mask, xsrc, ysrc, SRCAND) )
+ dc_mask, xsrcMask, ysrcMask, SRCAND) )
{
wxLogLastError(wxT("BitBlt"));
}
// tidy up temporary DCs and bitmap
::SelectObject(dc_mask, 0);
- ::DeleteDC(dc_mask);
::SelectObject(dc_buffer, 0);
- ::DeleteDC(dc_buffer);
- ::DeleteObject(buffer_bmap);
+
+#if !wxUSE_DC_CACHEING
+ {
+ ::DeleteDC(dc_mask);
+ ::DeleteDC(dc_buffer);
+ ::DeleteObject(buffer_bmap);
+ }
+#endif
}
}
else // no mask, just BitBlt() it
void wxDC::DoGetSize(int *w, int *h) const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES);
if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES);
}
void wxDC::DoGetSizeMM(int *w, int *h) const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE);
if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE);
}
wxSize wxDC::GetPPI() const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return wxSize();
+#endif
+
int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX);
int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY);
// For use by wxWindows only, unless custom units are required.
void wxDC::SetLogicalScale(double x, double y)
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
m_logicalScaleX = x;
m_logicalScaleY = y;
}
float *descent, float *externalLeading,
wxFont *theFont, bool use16bit) const
{
+#ifdef __WXMICROWIN__
+ if (!GetHDC()) return;
+#endif
+
wxCoord x1, y1, descent1, externalLeading1;
GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
*x = x1; *y = y1;
}
#endif
+#if wxUSE_DC_CACHEING
+
+/*
+ * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
+ * improve it in due course, either using arrays, or simply storing pointers to one
+ * entry for the bitmap, and two for the DCs. -- JACS
+ */
+
+wxList wxDC::sm_bitmapCache;
+wxList wxDC::sm_dcCache;
+
+wxDCCacheEntry::wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth)
+{
+ m_bitmap = hBitmap;
+ m_dc = 0;
+ m_width = w;
+ m_height = h;
+ m_depth = depth;
+}
+
+wxDCCacheEntry::wxDCCacheEntry(WXHDC hDC, int depth)
+{
+ m_bitmap = 0;
+ m_dc = hDC;
+ m_width = 0;
+ m_height = 0;
+ m_depth = depth;
+}
+
+wxDCCacheEntry::~wxDCCacheEntry()
+{
+ if (m_bitmap)
+ ::DeleteObject((HBITMAP) m_bitmap);
+ if (m_dc)
+ ::DeleteDC((HDC) m_dc);
+}
+
+wxDCCacheEntry* wxDC::FindBitmapInCache(WXHDC dc, int w, int h)
+{
+ int depth = ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
+ wxNode* node = sm_bitmapCache.First();
+ while (node)
+ {
+ wxDCCacheEntry* entry = (wxDCCacheEntry*) node->Data();
+
+ if (entry->m_depth == depth)
+ {
+ if (entry->m_width < w || entry->m_height < h)
+ {
+ ::DeleteObject((HBITMAP) entry->m_bitmap);
+ entry->m_bitmap = (WXHBITMAP) ::CreateCompatibleBitmap((HDC) dc, w, h);
+ if ( !entry->m_bitmap)
+ {
+ wxLogLastError(wxT("CreateCompatibleBitmap"));
+ }
+ entry->m_width = w; entry->m_height = h;
+ return entry;
+ }
+ return entry;
+ }
+
+ node = node->Next();
+ }
+ WXHBITMAP hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap((HDC) dc, w, h);
+ if ( !hBitmap)
+ {
+ wxLogLastError(wxT("CreateCompatibleBitmap"));
+ }
+ wxDCCacheEntry* entry = new wxDCCacheEntry(hBitmap, w, h, depth);
+ AddToBitmapCache(entry);
+ return entry;
+}
+
+wxDCCacheEntry* wxDC::FindDCInCache(wxDCCacheEntry* notThis, WXHDC dc)
+{
+ int depth = ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
+ wxNode* node = sm_dcCache.First();
+ while (node)
+ {
+ wxDCCacheEntry* entry = (wxDCCacheEntry*) node->Data();
+
+ // Don't return the same one as we already have
+ if (!notThis || (notThis != entry))
+ {
+ if (entry->m_depth == depth)
+ {
+ return entry;
+ }
+ }
+
+ node = node->Next();
+ }
+ WXHDC hDC = (WXHDC) ::CreateCompatibleDC((HDC) dc);
+ if ( !hDC)
+ {
+ wxLogLastError(wxT("CreateCompatibleDC"));
+ }
+ wxDCCacheEntry* entry = new wxDCCacheEntry(hDC, depth);
+ AddToDCCache(entry);
+ return entry;
+}
+
+void wxDC::AddToBitmapCache(wxDCCacheEntry* entry)
+{
+ sm_bitmapCache.Append(entry);
+}
+
+void wxDC::AddToDCCache(wxDCCacheEntry* entry)
+{
+ sm_dcCache.Append(entry);
+}
+
+void wxDC::ClearCache()
+{
+ sm_bitmapCache.DeleteContents(TRUE);
+ sm_bitmapCache.Clear();
+ sm_bitmapCache.DeleteContents(FALSE);
+ sm_dcCache.DeleteContents(TRUE);
+ sm_dcCache.Clear();
+ sm_dcCache.DeleteContents(FALSE);
+}
+
+// Clean up cache at app exit
+class wxDCModule : public wxModule
+{
+public:
+ virtual bool OnInit() { return TRUE; }
+ virtual void OnExit() { wxDC::ClearCache(); }
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxDCModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
+
+#endif
+ // wxUSE_DC_CACHEING