- DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
-public:
- inline wxXPMDataHandler(void)
- {
- m_name = "XPM bitmap data";
- m_extension = "xpm";
- m_type = wxBITMAP_TYPE_XPM_DATA;
- };
-
- virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
-};
-IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler, wxBitmapHandler)
-
-bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth)
-{
-#if wxUSE_XPM_IN_MSW
- XImage *ximage;
- int ErrorStatus;
- XpmAttributes xpmAttr;
- HDC dc;
-
- M_BITMAPHANDLERDATA->m_ok = FALSE;
- M_BITMAPHANDLERDATA->m_numColors = 0;
-
- dc = CreateCompatibleDC(NULL); /* memory DC */
-
- if (dc)
- {
- xpmAttr.valuemask = XpmReturnInfos; /* get infos back */
- ErrorStatus = XpmCreateImageFromData(&dc, (char **)data,
- &ximage, (XImage **) NULL, &xpmAttr);
-
- if (ErrorStatus == XpmSuccess)
- {
- /* ximage is malloced and contains bitmap and attributes */
- M_BITMAPHANDLERDATA->m_hBitmap = (WXHBITMAP) ximage->bitmap;
-
- BITMAP bm;
- GetObject((HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap, sizeof(bm), (LPSTR) & bm);
-
- M_BITMAPHANDLERDATA->m_width = (bm.bmWidth);
- M_BITMAPHANDLERDATA->m_height = (bm.bmHeight);
- M_BITMAPHANDLERDATA->m_depth = (bm.bmPlanes * bm.bmBitsPixel);
- M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels;
- XpmFreeAttributes(&xpmAttr);
-
- XImageFree(ximage); // releases the malloc, but does not detroy
- // the bitmap
- M_BITMAPHANDLERDATA->m_ok = TRUE;
- DeleteDC(dc);
-
- return TRUE;
- }
- else
- {
- M_BITMAPHANDLERDATA->m_ok = FALSE;
-// XpmDebugError(ErrorStatus, NULL);
- DeleteDC(dc);
- return FALSE;
- }
- }
-#endif
-
- return FALSE;