-/* TODO: bitmap handlers, a bit like this:
-class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
-{
- DECLARE_DYNAMIC_CLASS(wxBMPResourceHandler)
-public:
- inline wxBMPResourceHandler()
- {
- m_name = "Windows bitmap resource";
- m_extension = "";
- m_type = wxBITMAP_TYPE_BMP_RESOURCE;
- };
-
- virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
- int desiredWidth, int desiredHeight);
-};
-IMPLEMENT_DYNAMIC_CLASS(wxBMPResourceHandler, wxBitmapHandler)
-*/
-
-class WXDLLEXPORT wxXPMFileHandler: public wxBitmapHandler
-{
- DECLARE_DYNAMIC_CLASS(wxXPMFileHandler)
-public:
- inline wxXPMFileHandler(void)
- {
- m_name = "XPM bitmap file";
- m_extension = "xpm";
- m_type = wxBITMAP_TYPE_XPM;
- };
-
- virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
- int desiredWidth = -1, int desiredHeight = -1);
- virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
-};
-IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler)
-
-bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
- int desiredWidth, int desiredHeight)
-{
-#if USE_XPM_IN_MSW
- XImage *ximage;
- XpmAttributes xpmAttr;
- HDC dc;
-
- M_BITMAPHANDLERDATA->m_ok = FALSE;
- dc = CreateCompatibleDC(NULL);
- if (dc)
- {
- xpmAttr.valuemask = XpmReturnPixels;
- int errorStatus = XpmReadFileToImage(&dc, WXSTRINGCAST name, &ximage, (XImage **) NULL, &xpmAttr);
- DeleteDC(dc);
- if (errorStatus == XpmSuccess)
- {
- 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);
-
- M_BITMAPHANDLERDATA->m_ok = TRUE;
- return TRUE;
- }
- else
- {
- M_BITMAPHANDLERDATA->m_ok = FALSE;
- return FALSE;
- }
- }
-#endif
-
- return FALSE;
-}
-
-bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
-{
-#if USE_XPM_IN_MSW
- HDC dc = NULL;
-
- Visual *visual = NULL;
- XImage ximage;
-
- dc = CreateCompatibleDC(NULL);
- if (dc)
- {
- if (SelectObject(dc, (HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap))
- {
-
- ximage.width = M_BITMAPHANDLERDATA->m_width;
- ximage.height = M_BITMAPHANDLERDATA->m_height;
- ximage.depth = M_BITMAPHANDLERDATA->m_depth;
- ximage.bitmap = (void *)M_BITMAPHANDLERDATA->m_hBitmap;
- int errorStatus = XpmWriteFileFromImage(&dc, WXSTRINGCAST name,
- &ximage, (XImage *) NULL, (XpmAttributes *) NULL);
-
- if (dc)
- DeleteDC(dc);
-
- if (errorStatus == XpmSuccess)
- return TRUE;
- else
- return FALSE;
- } else return FALSE;
- } else return FALSE;
-#else
- return FALSE;
-#endif
-}
-
-
-class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
-{
- 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)
-{
- XImage * ximage;
- int ErrorStatus;
- XpmAttributes xpmAttr;
-
- xpmAttr.valuemask = XpmReturnInfos; // get infos back
- ErrorStatus = XpmCreateImageFromData( GetMainDevice() , (char **)data,
- &ximage, (XImage **) NULL, &xpmAttr);
-
- if (ErrorStatus == XpmSuccess)
- {
- M_BITMAPHANDLERDATA->m_ok = FALSE;
- M_BITMAPHANDLERDATA->m_numColors = 0;
- M_BITMAPHANDLERDATA->m_hBitmap = ximage->gworldptr ;
-
- M_BITMAPHANDLERDATA->m_width = ximage->width;
- M_BITMAPHANDLERDATA->m_height = ximage->height;
- M_BITMAPHANDLERDATA->m_depth = ximage->depth;
- M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels;
- XpmFreeAttributes(&xpmAttr);
- M_BITMAPHANDLERDATA->m_ok = TRUE;
- ximage->gworldptr = NULL ;
- XImageFree(ximage); // releases the malloc, but does not detroy
- // the bitmap
- M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
-
- return TRUE;
- }
- else
- {
- M_BITMAPHANDLERDATA->m_ok = FALSE;
- return FALSE;
- }
- return FALSE;
-}