#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();
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;
#ifdef __WXMICROWIN__
if (!GetHDC()) return FALSE;
#endif
-
+
wxMask *mask = NULL;
if ( useMask )
{
HBITMAP buffer_bmap ;
#if wxUSE_DC_CACHEING
- if (TRUE)
- {
- // 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, dest->GetHDC());
- dc_buffer = (HDC) dcCacheEntry2->m_dc;
-
- wxDCCacheEntry* bitmapCacheEntry = FindBitmapInCache(dest->GetHDC(),
- width, height);
-
- buffer_bmap = (HBITMAP) bitmapCacheEntry->m_bitmap;
- }
- else
-#endif
- {
- // create a temp buffer bitmap and DCs to access it and the mask
- dc_mask = ::CreateCompatibleDC(GetHdcOf(*source));
- dc_buffer = ::CreateCompatibleDC(GetHdc());
- buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
- ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap());
- ::SelectObject(dc_buffer, buffer_bmap);
- }
+ // 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
+ 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);
// copy dest to buffer
if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
#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;
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