]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/xpmhand.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: os2/xpmhand.cpp
3 // Purpose: wxBitmap: XPM handler and constructors
4 // Author: Julian Smart
5 // Modified for OS/2 by: Evgeny Kotsuba
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/os2/private.h"
42 #include "wx/xpmhand.h"
46 static void XpmToBitmap(
48 , const XImage
* pXimage
49 , const XImage
* pXmask
50 , const XpmAttributes
& rXpmAttr
53 wxBitmapRefData
* pRefData
= pBitmap
->GetBitmapData();
54 pRefData
->m_hBitmap
= (WXHBITMAP
)pXimage
->bitmap
;
57 // First set the bitmap width, height, depth...
61 if (!::GpiQueryBitmapParameters( GetHbitmapOf(*pBitmap
)
65 wxLogLastError(wxT("GetObject(pBitmap)"));
68 pRefData
->m_nWidth
= vBm
.cx
;
69 pRefData
->m_nHeight
= vBm
.cy
;
70 pRefData
->m_nDepth
= vBm
.cPlanes
* vBm
.cBitCount
;
71 pRefData
->m_nNumColors
= rXpmAttr
.npixels
;
75 wxMask
* pMask
= new wxMask();
77 pMask
->SetMaskBitmap((WXHBITMAP
) wxInvertMask( pXmask
->bitmap
81 pBitmap
->SetMask(pMask
);
83 } // end of XpmToBitmap
85 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
87 bool wxXPMFileHandler::LoadFile(
89 , const wxString
& rName
95 XImage
* pXimage
= NULL
;
96 XImage
* pXmask
= NULL
;
97 XpmAttributes vXpmAttr
;
100 DEVOPENSTRUC dOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
103 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&dOP
, NULLHANDLE
);
104 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSizl
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
107 vXpmAttr
.valuemask
= XpmReturnPixels
| XpmColorTable
;
109 int nErrorStatus
= XpmReadFileToImage( &hPS
110 ,wxMBSTRINGCAST rName
.fn_str()
117 if (nErrorStatus
== XpmSuccess
)
124 XpmFree(vXpmAttr
.pixels
);
125 XpmFreeAttributes(&vXpmAttr
);
128 XDestroyImage(pXmask
);
130 return pBitmap
->Ok();
133 } // end of wxXPMFileHandler::LoadFile
135 bool wxXPMFileHandler::SaveFile(
137 , const wxString
& rName
139 , const wxPalette
* pPalette
144 bool bHasmask
= FALSE
;
147 DEVOPENSTRUC dOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
150 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&dOP
, NULLHANDLE
);
151 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSizl
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
154 // fill the XImage struct 'by hand'
155 wxBitmapRefData
* pRefData
= pBitmap
->GetBitmapData();
157 vXimage
.width
= pRefData
->m_nWidth
;
158 vXimage
.height
= pRefData
->m_nHeight
;
159 vXimage
.depth
= pRefData
->m_nDepth
;
160 vXimage
.bitmap
= (HBITMAP
)pRefData
->m_hBitmap
;
162 bHasmask
= (pRefData
->m_pBitmapMask
!= NULL
);
166 // Strangely enough, the MSW version of xpmlib is not
167 // coherent with itself regarding masks; we have to invert
168 // the mask we get when loading, but we still must pass it
169 // 'as is' when saving...
171 vXmask
.bitmap
= (HBITMAP
)pRefData
->m_pBitmapMask
->GetMaskBitmap();
172 vXmask
.width
= pRefData
->m_nWidth
;
173 vXmask
.height
= pRefData
->m_nHeight
;
177 int nErrorStatus
= XpmWriteFileFromImage( &hPS
178 ,wxMBSTRINGCAST rName
.fn_str()
180 ,(bHasmask
? &vXmask
: (XImage
*)NULL
)
181 ,(XpmAttributes
*) NULL
185 return (nErrorStatus
== XpmSuccess
);
188 } // end of wxXPMFileHandler::SaveFile
190 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
192 bool wxXPMDataHandler::Create(
201 XImage
* pXimage
= NULL
;
202 XImage
* pXmask
= NULL
;
203 XpmAttributes vXpmAttr
;
206 DEVOPENSTRUC dOP
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
209 hDC
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&dOP
, NULLHANDLE
);
210 hPS
= ::GpiCreatePS(vHabmain
, hDC
, &vSizl
, PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
);
213 vXpmAttr
.valuemask
= XpmReturnInfos
| XpmColorTable
;
215 int nErrorStatus
= XpmCreateImageFromData( &hPS
223 if (nErrorStatus
== XpmSuccess
)
230 XpmFree(vXpmAttr
.pixels
);
231 XpmFreeAttributes(&vXpmAttr
);
232 XImageFree(pXimage
); // releases the malloc, but does not destroy bitmap
234 XDestroyImage(pXmask
);
236 return pBitmap
->Ok();
239 } // end of wxXPMDataHandler::Create
241 #endif // wxUSE_XPM_IN_OS2