For wxMSW, split XPM handler into separate file (please add handler explicitly in app);

doc changes espec. wxBitmap overview


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1416 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1999-01-16 22:17:13 +00:00
parent a4abc0fc8d
commit 2fd284a4a0
28 changed files with 1643 additions and 497 deletions

View File

@@ -37,11 +37,6 @@
#include "assert.h"
#if wxUSE_XPM_IN_MSW
#define FOR_MSW 1
#include "../src/xpm/xpm34.h"
#endif
#include "wx/msw/dib.h"
#if !USE_SHARED_LIBRARIES
@@ -146,6 +141,12 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
wxTheBitmapList->AddBitmap(this);
}
// Create from XPM data
wxBitmap::wxBitmap(char **data, wxItem *WXUNUSED(anItem))
{
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
}
wxBitmap::wxBitmap(int w, int h, int d)
{
(void)Create(w, h, d);
@@ -170,14 +171,6 @@ wxBitmap::wxBitmap(const wxString& filename, long type)
wxTheBitmapList->AddBitmap(this);
}
#if wxUSE_XPM_IN_MSW
// Create from data
wxBitmap::wxBitmap(char **data, wxItem *WXUNUSED(anItem))
{
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
}
#endif
bool wxBitmap::Create(int w, int h, int d)
{
UnRef();
@@ -696,169 +689,6 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type
#endif
}
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 wxUSE_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 wxUSE_XPM_IN_MSW
HDC dc = NULL;
XImage ximage;
dc = CreateCompatibleDC(NULL);
if (dc)
{
if (SelectObject(dc, (HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap))
{
/* for following SetPixel */
/* fill the XImage struct 'by hand' */
ximage.width = M_BITMAPHANDLERDATA->m_width;
ximage.height = M_BITMAPHANDLERDATA->m_height;
ximage.depth = M_BITMAPHANDLERDATA->m_depth;
ximage.bitmap = (HBITMAP)M_BITMAPHANDLERDATA->m_hBitmap;
int errorStatus = XpmWriteFileFromImage(&dc, WXSTRINGCAST name,
&ximage, (XImage *) NULL, (XpmAttributes *) NULL);
if (dc)
DeleteDC(dc);
if (errorStatus == XpmSuccess)
return TRUE; /* no error */
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)
{
#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;
}
void wxBitmap::CleanUpHandlers(void)
{
wxNode *node = sm_handlers.First();
@@ -876,8 +706,12 @@ void wxBitmap::InitStandardHandlers(void)
{
AddHandler(new wxBMPResourceHandler);
AddHandler(new wxBMPFileHandler);
AddHandler(new wxXPMFileHandler);
AddHandler(new wxXPMDataHandler);
// Not added by default: include xpmhand.h in your app
// and call these in your wxApp::OnInit.
// AddHandler(new wxXPMFileHandler);
// AddHandler(new wxXPMDataHandler);
AddHandler(new wxICOResourceHandler);
AddHandler(new wxICOFileHandler);
}