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 wxPixelDataBase
;
30 // ----------------------------------------------------------------------------
33 // NB: this class is private, but declared here to make it possible inline
34 // wxBitmap functions accessing it
35 // ----------------------------------------------------------------------------
37 class WXDLLIMPEXP_CORE wxBitmapRefData
: public wxGDIImageRefData
41 wxBitmapRefData(const wxBitmapRefData
&tocopy
);
42 virtual ~wxBitmapRefData() { Free(); }
48 wxPalette m_vBitmapPalette
;
54 wxDC
* m_pSelectedInto
;
57 // Optional mask for transparent drawing
59 wxMask
* m_pBitmapMask
;
60 }; // end of CLASS wxBitmapRefData
62 // ----------------------------------------------------------------------------
63 // wxBitmap: a mono or colour bitmap
64 // ----------------------------------------------------------------------------
66 class WXDLLIMPEXP_CORE wxBitmap
: public wxGDIImage
,
67 public wxBitmapHelpers
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(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 )
120 (void)Create(nWidth
, nHeight
, nDepth
);
122 wxBitmap( const wxSize
& sz
, int nDepth
= -1 )
125 (void)Create(sz
, nDepth
);
128 wxBitmap( const wxImage
& image
, int depth
= -1 )
129 { (void)CreateFromImage(image
, depth
); }
131 // we must have this, otherwise icons are silently copied into bitmaps using
132 // the copy ctor but the resulting bitmap is invalid!
133 inline wxBitmap(const wxIcon
& rIcon
)
134 { Init(); CopyFromIcon(rIcon
); }
136 wxBitmap
& operator=(const wxIcon
& rIcon
)
138 (void)CopyFromIcon(rIcon
);
143 wxBitmap
& operator=(const wxCursor
& rCursor
)
145 (void)CopyFromCursor(rCursor
);
151 wxImage
ConvertToImage() const;
152 wxBitmap
ConvertToDisabled(unsigned char brightness
= 255) const;
154 // get the given part of bitmap
155 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
157 // copies the contents and mask of the given (colour) icon to the bitmap
158 bool CopyFromIcon(const wxIcon
& rIcon
);
160 // copies the contents and mask of the given cursor to the bitmap
161 bool CopyFromCursor(const wxCursor
& rCursor
);
163 virtual bool Create( int nWidth
165 ,int nDepth
= wxBITMAP_SCREEN_DEPTH
167 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
)
168 { return Create(sz
.GetWidth(), sz
.GetHeight(), depth
); }
169 virtual bool Create(int width
, int height
, const wxDC
& WXUNUSED(dc
))
170 { return Create(width
,height
); }
172 virtual bool Create( const void* pData
178 virtual bool LoadFile( int nId
179 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
181 virtual bool LoadFile( const wxString
& rName
182 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
184 virtual bool SaveFile( const wxString
& rName
186 ,const wxPalette
* pCmap
= NULL
189 inline wxBitmapRefData
* GetBitmapData() const
190 { return (wxBitmapRefData
*)m_refData
; }
192 // raw bitmap access support functions
193 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
194 void UngetRawData(wxPixelDataBase
& data
);
196 inline int GetQuality() const
197 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
199 void SetQuality(int nQ
);
201 wxPalette
* GetPalette() const
202 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : NULL
); }
204 void SetPalette(const wxPalette
& rPalette
);
206 inline wxMask
* GetMask() const
207 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: NULL
); }
209 void SetMask(wxMask
* pMask
) ;
213 inline void SetHBITMAP(WXHBITMAP hBmp
)
214 { SetHandle((WXHANDLE
)hBmp
); }
216 inline WXHBITMAP
GetHBITMAP() const
217 { return (WXHBITMAP
)GetHandle(); }
219 inline void SetSelectedInto(wxDC
* pDc
)
220 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
222 inline wxDC
* GetSelectedInto() const
223 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: NULL
); }
225 inline bool IsMono(void) const { return m_bIsMono
; }
227 // An OS/2 version that probably doesn't do anything like the msw version
228 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
231 // common part of all ctors
234 inline virtual wxGDIImageRefData
* CreateData() const
235 { return new wxBitmapRefData
; }
237 bool CreateFromImage(const wxImage
& image
, int depth
);
239 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
242 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
245 DECLARE_DYNAMIC_CLASS(wxBitmap
)
246 }; // end of CLASS wxBitmap
248 // ----------------------------------------------------------------------------
249 // wxMask: a mono bitmap used for drawing bitmaps transparently.
250 // ----------------------------------------------------------------------------
252 class WXDLLIMPEXP_CORE wxMask
: public wxObject
256 wxMask( const wxMask
& tocopy
);
258 // Construct a mask from a bitmap and a colour indicating the transparent
260 wxMask( const wxBitmap
& rBitmap
261 ,const wxColour
& rColour
264 // Construct a mask from a bitmap and a palette index indicating the
266 wxMask( const wxBitmap
& rBitmap
270 // Construct a mask from a mono bitmap (copies the bitmap).
271 wxMask(const wxBitmap
& rBitmap
);
273 // construct a mask from the givne bitmap handle
274 wxMask(WXHBITMAP hBmp
)
275 { m_hMaskBitmap
= hBmp
; }
279 bool Create( const wxBitmap
& bitmap
280 ,const wxColour
& rColour
282 bool Create( const wxBitmap
& rBitmap
285 bool Create(const wxBitmap
& rBitmap
);
288 WXHBITMAP
GetMaskBitmap() const
289 { return m_hMaskBitmap
; }
290 void SetMaskBitmap(WXHBITMAP hBmp
)
291 { m_hMaskBitmap
= hBmp
; }
294 WXHBITMAP m_hMaskBitmap
;
295 DECLARE_DYNAMIC_CLASS(wxMask
)
296 }; // end of CLASS wxMask
298 // ----------------------------------------------------------------------------
299 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
300 // ----------------------------------------------------------------------------
302 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxGDIImageHandler
305 inline wxBitmapHandler()
306 { m_lType
= wxBITMAP_TYPE_INVALID
; }
308 inline wxBitmapHandler( const wxString
& rName
309 ,const wxString
& rExt
312 : wxGDIImageHandler( rName
318 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
319 // old class which worked only with bitmaps
320 virtual bool Create( wxBitmap
* pBitmap
327 virtual bool LoadFile( wxBitmap
* pBitmap
333 virtual bool LoadFile( wxBitmap
* pBitmap
334 ,const wxString
& rName
339 virtual bool SaveFile( wxBitmap
* pBitmap
340 ,const wxString
& rName
342 ,const wxPalette
* pPalette
= NULL
345 virtual bool Create( wxGDIImage
* pImage
352 virtual bool Load( wxGDIImage
* pImage
358 virtual bool Save( const wxGDIImage
* pImage
359 ,const wxString
& rName
363 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
364 ,const wxString
& WXUNUSED(rName
)
365 ,WXHANDLE
WXUNUSED(hPs
)
366 ,wxBitmapType
WXUNUSED(lFlags
)
367 ,int WXUNUSED(nDesiredWidth
)
368 ,int WXUNUSED(nDesiredHeight
)
371 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
372 }; // end of CLASS wxBitmapHandler