1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/msw/gdiimage.h"
16 #include "wx/palette.h"
18 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
19 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
20 class WXDLLIMPEXP_FWD_CORE wxBitmapRefData
;
21 class WXDLLIMPEXP_FWD_CORE wxControl
;
22 class WXDLLIMPEXP_FWD_CORE wxCursor
;
23 class WXDLLIMPEXP_FWD_CORE wxDC
;
25 class WXDLLIMPEXP_FWD_CORE wxDIB
;
27 class WXDLLIMPEXP_FWD_CORE wxIcon
;
28 class WXDLLIMPEXP_FWD_CORE wxImage
;
29 class WXDLLIMPEXP_FWD_CORE wxMask
;
30 class WXDLLIMPEXP_FWD_CORE wxPalette
;
31 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase
;
33 // What kind of transparency should a bitmap copied from an icon or cursor
35 enum wxBitmapTransparency
37 wxBitmapTransparency_Auto
, // default: copy alpha if the source has it
38 wxBitmapTransparency_None
, // never create alpha
39 wxBitmapTransparency_Always
// always use alpha
42 // ----------------------------------------------------------------------------
43 // wxBitmap: a mono or colour bitmap
44 // NOTE: for wxMSW we don't use the wxBitmapBase base class declared in bitmap.h!
45 // ----------------------------------------------------------------------------
47 class WXDLLIMPEXP_CORE wxBitmap
: public wxGDIImage
50 // default ctor creates an invalid bitmap, you must Create() it later
53 // Initialize with raw data
54 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
56 // Initialize with XPM data
57 wxBitmap(const char* const* data
);
61 *this = wxBitmap(wx_const_cast(const char* const*, data
));
65 // Load a file or resource
66 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
68 // New constructor for generalised creation from data
69 wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
71 // Create a new, uninitialized bitmap of the given size and depth (if it
72 // is omitted, will create a bitmap compatible with the display)
74 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
75 // taking a DC argument if you want to force using DDB in this case
76 wxBitmap(int width
, int height
, int depth
= -1);
78 // Create a bitmap compatible with the given DC
79 wxBitmap(int width
, int height
, const wxDC
& dc
);
82 // Convert from wxImage
83 wxBitmap(const wxImage
& image
, int depth
= -1)
84 { (void)CreateFromImage(image
, depth
); }
86 // Create a DDB compatible with the given DC from wxImage
87 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
88 { (void)CreateFromImage(image
, dc
); }
91 // we must have this, otherwise icons are silently copied into bitmaps using
92 // the copy ctor but the resulting bitmap is invalid!
93 wxBitmap(const wxIcon
& icon
,
94 wxBitmapTransparency transp
= wxBitmapTransparency_Auto
)
96 CopyFromIcon(icon
, transp
);
99 wxBitmap
& operator=(const wxIcon
& icon
)
101 (void)CopyFromIcon(icon
);
106 wxBitmap
& operator=(const wxCursor
& cursor
)
108 (void)CopyFromCursor(cursor
);
116 wxImage
ConvertToImage() const;
117 #endif // wxUSE_IMAGE
119 // get the given part of bitmap
120 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
122 // NB: This should not be called from user code. It is for wx internal
124 wxBitmap
GetSubBitmapOfHDC( const wxRect
& rect
, WXHDC hdc
) const;
126 // copies the contents and mask of the given (colour) icon to the bitmap
127 bool CopyFromIcon(const wxIcon
& icon
,
128 wxBitmapTransparency transp
= wxBitmapTransparency_Auto
);
130 // copies the contents and mask of the given cursor to the bitmap
131 bool CopyFromCursor(const wxCursor
& cursor
,
132 wxBitmapTransparency transp
= wxBitmapTransparency_Auto
);
135 // copies from a device independent bitmap
136 bool CopyFromDIB(const wxDIB
& dib
);
139 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
140 virtual bool Create(int width
, int height
, const wxDC
& dc
);
141 virtual bool Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
142 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
143 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
145 wxBitmapRefData
*GetBitmapData() const
146 { return (wxBitmapRefData
*)m_refData
; }
148 // raw bitmap access support functions
149 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
150 void UngetRawData(wxPixelDataBase
& data
);
153 wxPalette
* GetPalette() const;
154 void SetPalette(const wxPalette
& palette
);
155 #endif // wxUSE_PALETTE
157 wxMask
*GetMask() const;
158 wxBitmap
GetMaskBitmap() const;
159 void SetMask(wxMask
*mask
);
161 // these functions are internal and shouldn't be used, they risk to
162 // disappear in the future
163 bool HasAlpha() const;
166 // implementation only from now on
167 // -------------------------------
170 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
171 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
174 void SetSelectedInto(wxDC
*dc
);
175 wxDC
*GetSelectedInto() const;
176 #endif // __WXDEBUG__
179 virtual wxGDIImageRefData
*CreateData() const;
180 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
182 // creates an uninitialized bitmap, called from Create()s above
183 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
186 // creates the bitmap from wxImage, supposed to be called from ctor
187 bool CreateFromImage(const wxImage
& image
, int depth
);
189 // creates a DDB from wxImage, supposed to be called from ctor
190 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
192 // common part of the 2 methods above (hdc may be 0)
193 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
194 #endif // wxUSE_IMAGE
197 // common part of CopyFromIcon/CopyFromCursor for Win32
199 CopyFromIconOrCursor(const wxGDIImage
& icon
,
200 wxBitmapTransparency transp
= wxBitmapTransparency_Auto
);
203 DECLARE_DYNAMIC_CLASS(wxBitmap
)
206 // ----------------------------------------------------------------------------
207 // wxMask: a mono bitmap used for drawing bitmaps transparently.
208 // ----------------------------------------------------------------------------
210 class WXDLLIMPEXP_CORE wxMask
: public wxObject
216 wxMask(const wxMask
&mask
);
218 // Construct a mask from a bitmap and a colour indicating the transparent
220 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
222 // Construct a mask from a bitmap and a palette index indicating the
224 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
226 // Construct a mask from a mono bitmap (copies the bitmap).
227 wxMask(const wxBitmap
& bitmap
);
229 // construct a mask from the givne bitmap handle
230 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
234 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
235 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
236 bool Create(const wxBitmap
& bitmap
);
239 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
240 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
243 WXHBITMAP m_maskBitmap
;
245 DECLARE_DYNAMIC_CLASS(wxMask
)
249 // ----------------------------------------------------------------------------
250 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
251 // NOTE: for wxMSW we don't use the wxBitmapHandler class declared in bitmap.h!
252 // ----------------------------------------------------------------------------
254 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxGDIImageHandler
257 wxBitmapHandler() { }
258 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, wxBitmapType type
)
259 : wxGDIImageHandler(name
, ext
, type
) { }
261 // implement wxGDIImageHandler's pure virtuals:
263 virtual bool Create(wxGDIImage
*image
,
266 int width
, int height
, int depth
= 1);
267 virtual bool Load(wxGDIImage
*image
,
268 const wxString
& name
,
270 int desiredWidth
, int desiredHeight
);
271 virtual bool Save(const wxGDIImage
*image
,
272 const wxString
& name
,
273 wxBitmapType type
) const;
276 // make wxBitmapHandler compatible with the wxBitmapHandler interface
277 // declared in bitmap.h, even if it's derived from wxGDIImageHandler:
279 virtual bool Create(wxBitmap
*bitmap
,
282 int width
, int height
, int depth
= 1);
283 virtual bool LoadFile(wxBitmap
*bitmap
,
284 const wxString
& name
,
286 int desiredWidth
, int desiredHeight
);
287 virtual bool SaveFile(const wxBitmap
*bitmap
,
288 const wxString
& name
,
290 const wxPalette
*palette
= NULL
) const;
293 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)