- c2pstrcpy( (StringPtr) theName , name ) ;
-#else
- strcpy( (char *) theName , name ) ;
- c2pstr( (char *)theName ) ;
-#endif
-
- PicHandle thePict = (PicHandle ) GetNamedResource( 'PICT' , theName ) ;
- if ( thePict )
- {
- PictInfo theInfo ;
-
- GetPictInfo( thePict , &theInfo , 0 , 0 , systemMethod , 0 ) ;
- DetachResource( (Handle) thePict ) ;
- M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypePict ;
- M_BITMAPHANDLERDATA->m_hPict = thePict ;
- M_BITMAPHANDLERDATA->m_width = theInfo.sourceRect.right - theInfo.sourceRect.left ;
- M_BITMAPHANDLERDATA->m_height = theInfo.sourceRect.bottom - theInfo.sourceRect.top ;
-
- M_BITMAPHANDLERDATA->m_depth = theInfo.depth ;
- M_BITMAPHANDLERDATA->m_ok = true ;
- M_BITMAPHANDLERDATA->m_numColors = theInfo.uniqueColors ;
-// M_BITMAPHANDLERDATA->m_bitmapPalette;
-// M_BITMAPHANDLERDATA->m_quality;
- return TRUE ;
- }
- return FALSE ;
-}
-
-/* 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;