]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/xpmhand.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap: XPM handler and constructors
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "xpmhand.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/palette.h"
28 #include "wx/dcmemory.h"
29 #include "wx/bitmap.h"
33 #include "wx/msw/private.h"
38 #include "../xpm/xpm34.h"
41 #include "wx/xpmhand.h"
42 #include "wx/msw/dib.h"
46 static void XpmToBitmap(wxBitmap
*bitmap
,
48 const XpmAttributes
& xpmAttr
)
50 wxBitmapRefData
*refData
= bitmap
->GetBitmapData();
51 refData
->m_hBitmap
= (WXHBITMAP
)ximage
->bitmap
;
54 if ( !::GetObject(GetHbitmapOf(*bitmap
), sizeof(bm
), (LPSTR
) & bm
) )
56 wxLogLastError("GetObject(bitmap)");
59 refData
->m_width
= bm
.bmWidth
;
60 refData
->m_height
= bm
.bmHeight
;
61 refData
->m_depth
= bm
.bmPlanes
* bm
.bmBitsPixel
;
62 refData
->m_numColors
= xpmAttr
.npixels
;
65 #endif // wxUSE_XPM_IN_MSW
67 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
69 bool wxXPMFileHandler::LoadFile(wxBitmap
*bitmap
,
72 int desiredWidth
, int desiredHeight
)
76 XpmAttributes xpmAttr
;
79 dc
= CreateCompatibleDC(NULL
);
82 xpmAttr
.valuemask
= XpmReturnPixels
;
83 int errorStatus
= XpmReadFileToImage(&dc
, wxMBSTRINGCAST name
.fn_str(), &ximage
, (XImage
**) NULL
, &xpmAttr
);
85 if (errorStatus
== XpmSuccess
)
87 XpmToBitmap(bitmap
, ximage
, xpmAttr
);
89 XpmFreeAttributes(&xpmAttr
);
93 #if WXWIN_COMPATIBILITY_2
94 bitmap
->SetOk(errorStatus
== XpmSuccess
);
95 #endif // WXWIN_COMPATIBILITY_2
104 bool wxXPMFileHandler::SaveFile(wxBitmap
*bitmap
,
105 const wxString
& name
,
107 const wxPalette
*palette
)
114 dc
= CreateCompatibleDC(NULL
);
117 if ( SelectObject(dc
, GetHbitmapOf(*bitmap
)) )
119 /* for following SetPixel */
120 /* fill the XImage struct 'by hand' */
121 wxBitmapRefData
*refData
= bitmap
->GetBitmapData();
122 ximage
.width
= refData
->m_width
;
123 ximage
.height
= refData
->m_height
;
124 ximage
.depth
= refData
->m_depth
;
125 ximage
.bitmap
= (HBITMAP
)refData
->m_hBitmap
;
126 int errorStatus
= XpmWriteFileFromImage(&dc
, wxMBSTRINGCAST name
.fn_str(),
127 &ximage
, (XImage
*) NULL
,
128 (XpmAttributes
*) NULL
);
133 if (errorStatus
== XpmSuccess
)
134 return TRUE
; /* no error */
144 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
146 bool wxXPMDataHandler::Create(wxBitmap
*bitmap
,
156 XpmAttributes xpmAttr
;
159 dc
= CreateCompatibleDC(NULL
); /* memory DC */
163 xpmAttr
.valuemask
= XpmReturnInfos
; /* get infos back */
164 ErrorStatus
= XpmCreateImageFromData(&dc
, (char **)data
,
165 &ximage
, (XImage
**) NULL
, &xpmAttr
);
167 if (ErrorStatus
== XpmSuccess
)
169 XpmToBitmap(bitmap
, ximage
, xpmAttr
);
171 XpmFreeAttributes(&xpmAttr
);
173 XImageFree(ximage
); // releases the malloc, but does not detroy
178 // XpmDebugError(ErrorStatus, NULL);
183 #if WXWIN_COMPATIBILITY_2
184 bitmap
->SetOk(errorStatus
== XpmSuccess
);
185 #endif // WXWIN_COMPATIBILITY_2