+#endif
+
+// Gets an HDC for the specified printer configuration
+WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst)
+{
+ wxPrintData printData = printDataConst;
+ printData.ConvertToNative();
+
+ wxChar* driverName = (wxChar*) NULL;
+
+ wxString devNameStr = printData.GetPrinterName();
+ wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
+
+ const wxChar* deviceName;
+ if ( !devNameStr )
+ deviceName = (wxChar*) NULL;
+ else
+ deviceName = devNameStr.c_str();
+
+ LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
+
+ HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
+
+ if ( hDevMode )
+ lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
+
+ if ( !devNameStr )
+ {
+ // Retrieve the default device name
+ wxString portName;
+#ifdef __WXDEBUG__
+ bool ret =
+#else // !Debug
+ (void)
+#endif // Debug/Release
+ wxGetDefaultDeviceName(devNameStr, portName);
+
+ wxASSERT_MSG( ret, wxT("Could not get default device name.") );
+
+ deviceName = devNameStr.c_str();
+ }
+
+#ifdef __WIN32__
+ HDC hDC = CreateDC(driverName, deviceName, portName, (DEVMODE *) lpDevMode);
+#else
+ HDC hDC = CreateDC(driverName, deviceName, portName, (LPSTR) lpDevMode);
+#endif
+
+ if (hDevMode && lpDevMode)
+ GlobalUnlock(hDevMode);
+
+ return (WXHDC) hDC;
+}
+
+// ----------------------------------------------------------------------------
+// wxPrinterDC bit blitting/bitmap drawing
+// ----------------------------------------------------------------------------
+
+// Win16 doesn't define GDI_ERROR.
+#ifndef GDI_ERROR
+#define GDI_ERROR -1
+#endif
+
+void wxPrinterDC::DoDrawBitmap(const wxBitmap &bmp,
+ wxCoord x, wxCoord y,
+ bool useMask)
+{
+ wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") );
+
+ int width = bmp.GetWidth(),
+ height = bmp.GetHeight();
+
+ if ( ::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHDIB )
+ {
+ BITMAPINFO *info = (BITMAPINFO *) malloc( sizeof( BITMAPINFOHEADER ) + 256 * sizeof(RGBQUAD ) );
+ memset( info, 0, sizeof( BITMAPINFOHEADER ) );
+
+ int iBitsSize = ((width + 3 ) & ~3 ) * height;
+
+ void* bits = malloc( iBitsSize );
+
+ info->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
+ info->bmiHeader.biWidth = width;
+ info->bmiHeader.biHeight = height;
+ info->bmiHeader.biPlanes = 1;
+ info->bmiHeader.biBitCount = 8;
+ info->bmiHeader.biCompression = BI_RGB;
+
+ ScreenHDC display;
+ if ( GetDIBits(display, GetHbitmapOf(bmp), 0,
+ bmp.GetHeight(), bits, info,
+ DIB_RGB_COLORS) )
+ {
+ if ( ::StretchDIBits(GetHdc(), x, y,
+ width, height,
+ 0 , 0, width, height,
+ bits, info,
+ DIB_RGB_COLORS, SRCCOPY) == GDI_ERROR )
+ {
+ wxLogLastError(wxT("StretchDIBits"));
+ }
+ }
+
+ free(bits);
+ free(info);
+ }
+ else // no support for StretchDIBits()
+ {
+ wxMemoryDC memDC;
+ memDC.SelectObject(bmp);
+
+ Blit(x, y, width, height, &memDC, 0, 0, wxCOPY, useMask);
+
+ memDC.SelectObject(wxNullBitmap);
+ }
+}