1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/os2/private.h"
16 #include "wx/os2/gdiimage.h"
17 #include "wx/gdicmn.h"
18 #include "wx/palette.h"
20 class WXDLLIMPEXP_FWD_CORE wxDC
;
21 class WXDLLIMPEXP_FWD_CORE wxControl
;
22 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
23 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
24 class WXDLLIMPEXP_FWD_CORE wxIcon
;
25 class WXDLLIMPEXP_FWD_CORE wxMask
;
26 class WXDLLIMPEXP_FWD_CORE wxCursor
;
27 class WXDLLIMPEXP_FWD_CORE wxControl
;
28 class WXDLLIMPEXP_FWD_CORE wxImage
;
29 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase
;
31 // ----------------------------------------------------------------------------
34 // NB: this class is private, but declared here to make it possible inline
35 // wxBitmap functions accessing it
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE wxBitmapRefData
: public wxGDIImageRefData
42 wxBitmapRefData(const wxBitmapRefData
&tocopy
);
43 virtual ~wxBitmapRefData() { Free(); }
49 wxPalette m_vBitmapPalette
;
55 wxDC
* m_pSelectedInto
;
58 // Optional mask for transparent drawing
60 wxMask
* m_pBitmapMask
;
61 }; // end of CLASS wxBitmapRefData
63 // ----------------------------------------------------------------------------
64 // wxBitmap: a mono or colour bitmap
65 // ----------------------------------------------------------------------------
67 class WXDLLIMPEXP_CORE wxBitmap
: public wxGDIImage
70 // default ctor creates an invalid bitmap, you must Create() it later
71 wxBitmap() { Init(); }
74 inline wxBitmap(const wxBitmap
& rBitmap
)
78 SetHandle(rBitmap
.GetHandle());
81 // Initialize with raw data
82 wxBitmap( const char bits
[]
88 // Initialize with XPM data
89 wxBitmap(const char* const* bits
);
94 *this = wxBitmap(wx_const_cast(const char* const*, data
));
100 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
103 // For compatiability with other ports, under OS/2 does same as default ctor
104 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
105 ,wxBitmapType
WXUNUSED(lType
)
108 // New constructor for generalised creation from data
109 wxBitmap( const void* pData
116 // If depth is omitted, will create a bitmap compatible with the display
117 wxBitmap( int nWidth
, int nHeight
, int nDepth
= -1 );
119 wxBitmap( const wxImage
& image
, int depth
= -1 )
120 { (void)CreateFromImage(image
, depth
); }
122 // we must have this, otherwise icons are silently copied into bitmaps using
123 // the copy ctor but the resulting bitmap is invalid!
124 inline wxBitmap(const wxIcon
& rIcon
)
125 { Init(); CopyFromIcon(rIcon
); }
127 wxBitmap
& operator=(const wxIcon
& rIcon
)
129 (void)CopyFromIcon(rIcon
);
134 wxBitmap
& operator=(const wxCursor
& rCursor
)
136 (void)CopyFromCursor(rCursor
);
142 wxImage
ConvertToImage() const;
144 // get the given part of bitmap
145 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
147 // copies the contents and mask of the given (colour) icon to the bitmap
148 bool CopyFromIcon(const wxIcon
& rIcon
);
150 // copies the contents and mask of the given cursor to the bitmap
151 bool CopyFromCursor(const wxCursor
& rCursor
);
153 virtual bool Create( int nWidth
157 virtual bool Create( const void* pData
163 virtual bool LoadFile( int nId
164 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
166 virtual bool LoadFile( const wxString
& rName
167 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
169 virtual bool SaveFile( const wxString
& rName
171 ,const wxPalette
* pCmap
= NULL
174 inline wxBitmapRefData
* GetBitmapData() const
175 { return (wxBitmapRefData
*)m_refData
; }
177 // raw bitmap access support functions
178 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
179 void UngetRawData(wxPixelDataBase
& data
);
181 inline int GetQuality() const
182 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
184 void SetQuality(int nQ
);
186 wxPalette
* GetPalette() const
187 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
189 void SetPalette(const wxPalette
& rPalette
);
191 inline wxMask
* GetMask() const
192 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
194 void SetMask(wxMask
* pMask
) ;
198 inline void SetHBITMAP(WXHBITMAP hBmp
)
199 { SetHandle((WXHANDLE
)hBmp
); }
201 inline WXHBITMAP
GetHBITMAP() const
202 { return (WXHBITMAP
)GetHandle(); }
204 inline void SetSelectedInto(wxDC
* pDc
)
205 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
207 inline wxDC
* GetSelectedInto() const
208 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
210 inline bool IsMono(void) const { return m_bIsMono
; }
212 // An OS/2 version that probably doesn't do anything like the msw version
213 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
216 // common part of all ctors
219 inline virtual wxGDIImageRefData
* CreateData() const
220 { return new wxBitmapRefData
; }
222 bool CreateFromImage(const wxImage
& image
, int depth
);
224 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
227 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
230 DECLARE_DYNAMIC_CLASS(wxBitmap
)
231 }; // end of CLASS wxBitmap
233 // ----------------------------------------------------------------------------
234 // wxMask: a mono bitmap used for drawing bitmaps transparently.
235 // ----------------------------------------------------------------------------
237 class WXDLLIMPEXP_CORE wxMask
: public wxObject
241 wxMask( const wxMask
& tocopy
);
243 // Construct a mask from a bitmap and a colour indicating the transparent
245 wxMask( const wxBitmap
& rBitmap
246 ,const wxColour
& rColour
249 // Construct a mask from a bitmap and a palette index indicating the
251 wxMask( const wxBitmap
& rBitmap
255 // Construct a mask from a mono bitmap (copies the bitmap).
256 wxMask(const wxBitmap
& rBitmap
);
258 // construct a mask from the givne bitmap handle
259 wxMask(WXHBITMAP hBmp
)
260 { m_hMaskBitmap
= hBmp
; }
264 bool Create( const wxBitmap
& bitmap
265 ,const wxColour
& rColour
267 bool Create( const wxBitmap
& rBitmap
270 bool Create(const wxBitmap
& rBitmap
);
273 WXHBITMAP
GetMaskBitmap() const
274 { return m_hMaskBitmap
; }
275 void SetMaskBitmap(WXHBITMAP hBmp
)
276 { m_hMaskBitmap
= hBmp
; }
279 WXHBITMAP m_hMaskBitmap
;
280 DECLARE_DYNAMIC_CLASS(wxMask
)
281 }; // end of CLASS wxMask
283 // ----------------------------------------------------------------------------
284 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
285 // ----------------------------------------------------------------------------
287 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxGDIImageHandler
290 inline wxBitmapHandler()
291 { m_lType
= wxBITMAP_TYPE_INVALID
; }
293 inline wxBitmapHandler( const wxString
& rName
294 ,const wxString
& rExt
297 : wxGDIImageHandler( rName
303 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
304 // old class which worked only with bitmaps
305 virtual bool Create( wxBitmap
* pBitmap
312 virtual bool LoadFile( wxBitmap
* pBitmap
318 virtual bool LoadFile( wxBitmap
* pBitmap
319 ,const wxString
& rName
324 virtual bool SaveFile( wxBitmap
* pBitmap
325 ,const wxString
& rName
327 ,const wxPalette
* pPalette
= NULL
330 virtual bool Create( wxGDIImage
* pImage
337 virtual bool Load( wxGDIImage
* pImage
343 virtual bool Save( const wxGDIImage
* pImage
344 ,const wxString
& rName
348 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
349 ,const wxString
& WXUNUSED(rName
)
350 ,WXHANDLE
WXUNUSED(hPs
)
351 ,wxBitmapType
WXUNUSED(lFlags
)
352 ,int WXUNUSED(nDesiredWidth
)
353 ,int WXUNUSED(nDesiredHeight
)
356 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
357 }; // end of CLASS wxBitmapHandler