#include "wx/icon.h"
#endif
-#include "wx/settings.h"
+#include "wx/sysopt.h"
#include "wx/dcprint.h"
+#include "wx/module.h"
#include <string.h>
#include <math.h>
#include "wx/msw/private.h" // needs to be before #include <commdlg.h>
-#if wxUSE_COMMON_DIALOGS
+#if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
#include <commdlg.h>
#endif
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);
+ ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, FALSE);
}
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;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
RECT rect;
GetClipBox(GetHdc(), &rect);
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_clipping = TRUE;
// the region coords are always the device ones, so do the translation
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxCHECK_RET( GetHrgnOf(region), wxT("invalid clipping region") );
m_clipping = TRUE;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
if (m_clipping && m_hDC)
{
// TODO: this should restore the previous clipping region,
#ifdef __WXMICROWIN__
if (!GetHDC()) return 16;
#endif
-
+
return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL);
}
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
RECT rect;
if ( m_canvas )
{
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y),
col.GetPixel(),
style == wxFLOOD_SURFACE ? FLOODFILLSURFACE
#ifdef __WXMICROWIN__
if (!GetHDC()) return FALSE;
#endif
-
+
wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel") );
// get the color of the pixel
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxCoord x1 = x-VIEWPORT_EXTENT;
wxCoord y1 = y-VIEWPORT_EXTENT;
wxCoord x2 = x+VIEWPORT_EXTENT;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
(void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL);
(void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2));
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
double dx = xc - x1;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxCoord x2 = x1 + width,
y2 = y1 + height;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
COLORREF color = 0x00ffffff;
if (m_pen.Ok())
{
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
// Do things less efficiently if we have offsets
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
// Do things less efficiently if we have offsets
if (xoffset != 0 || yoffset != 0)
{
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
wxCoord x2 = x + width;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
// Now, a negative radius value is interpreted to mean
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
wxCoord x2 = (x+width);
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
wxCoord x2 = x + w;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxCHECK_RET( icon.Ok(), wxT("invalid icon in DrawIcon") );
#ifdef __WIN32__
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxDC::DrawBitmap") );
int width = bmp.GetWidth(),
HBITMAP hbmpMask = 0;
+#if wxUSE_PALETTE
+ HPALETTE oldPal = 0;
+#endif // wxUSE_PALETTE
+
if ( useMask )
{
wxMask *mask = bmp.GetMask();
// than the wxWindows fall-back implementation. So we need
// to be able to switch this on and off at runtime.
bool ok = FALSE;
- if (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
+#if wxUSE_SYSTEM_OPTIONS
+ if (wxSystemOptions::GetOptionInt(wxT("no-maskblt")) == 0)
+#endif
{
+ HDC cdc = GetHdc();
HDC hdcMem = ::CreateCompatibleDC(GetHdc());
::SelectObject(hdcMem, GetHbitmapOf(bmp));
- ok = ::MaskBlt(GetHdc(), x, y, width, height,
+#if wxUSE_PALETTE
+ wxPalette *pal = bmp.GetPalette();
+ if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
+ {
+ oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(pal), FALSE);
+ ::RealizePalette(hdcMem);
+ }
+#endif // wxUSE_PALETTE
+
+ ok = ::MaskBlt(cdc, x, y, width, height,
hdcMem, 0, 0,
hbmpMask, 0, 0,
MAKEROP4(SRCCOPY, DSTCOPY)) != 0;
+
+#if wxUSE_PALETTE
+ if (oldPal)
+ ::SelectPalette(hdcMem, oldPal, FALSE);
+#endif // wxUSE_PALETTE
+
::DeleteDC(hdcMem);
}
::SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() );
}
+#if wxUSE_PALETTE
+ wxPalette *pal = bmp.GetPalette();
+ if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
+ {
+ oldPal = ::SelectPalette(memdc, GetHpaletteOf(pal), FALSE);
+ ::RealizePalette(memdc);
+ }
+#endif // wxUSE_PALETTE
+
::SelectObject( memdc, hbitmap );
::BitBlt( cdc, x, y, width, height, memdc, 0, 0, SRCCOPY);
+
+#if wxUSE_PALETTE
+ if (oldPal)
+ ::SelectPalette(memdc, oldPal, FALSE);
+#endif // wxUSE_PALETTE
+
::DeleteDC( memdc );
::SetTextColor(GetHdc(), old_textground);
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
DrawAnyText(text, x, y);
// update the bounding box
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
// prepare for drawing the text
if ( m_textForegroundColour.Ok() )
SetTextColor(GetHdc(), m_textForegroundColour.GetPixel());
#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
#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 )
// 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)
{
- ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE);
+ ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, FALSE);
m_oldPalette = 0;
}
// the original colourmap
if (m_oldPalette)
{
- ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE);
+ ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, FALSE);
m_oldPalette = 0;
}
if (m_palette.Ok() && m_palette.GetHPALETTE())
{
- HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), TRUE);
+ HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), FALSE);
if (!m_oldPalette)
m_oldPalette = (WXHPALETTE) oldPal;
}
}
+#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)
#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)
#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)
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_backgroundBrush = brush;
if (!m_backgroundBrush.Ok())
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_backgroundMode = mode;
// SetBackgroundColour now only refers to text background
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_logicalFunction = function;
SetRop(m_hDC);
#ifdef __WXMICROWIN__
if (!GetHDC()) return 0;
#endif
-
+
TEXTMETRIC lpTextMetric;
GetTextMetrics(GetHdc(), &lpTextMetric);
#ifdef __WXMICROWIN__
if (!GetHDC()) return 0;
#endif
-
+
TEXTMETRIC lpTextMetric;
GetTextMetrics(GetHdc(), &lpTextMetric);
return;
}
#endif
-
+
HFONT hfontOld;
if ( font )
{
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_mappingMode = mode;
int pixel_width = 0;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_userScaleX = x;
m_userScaleY = y;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_signX = xLeftRight ? 1 : -1;
m_signY = yBottomUp ? -1 : 1;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_scaleX = x;
m_scaleY = y;
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_logicalOriginX = x;
m_logicalOriginY = 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())
// 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 (wxSystemSettings::GetOptionInt(wxT("no-maskblt")) == 0)
+#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;
}
#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
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES);
if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES);
}
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE);
if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE);
}
#ifdef __WXMICROWIN__
if (!GetHDC()) return wxSize();
#endif
-
+
int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX);
int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY);
#ifdef __WXMICROWIN__
if (!GetHDC()) return;
#endif
-
+
m_logicalScaleX = x;
m_logicalScaleY = y;
}
#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