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 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "bitmap.h"
19 #include "wx/msw/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
23 class WXDLLEXPORT wxBitmap
;
24 class WXDLLEXPORT wxBitmapHandler
;
25 class WXDLLEXPORT wxBitmapRefData
;
26 class WXDLLEXPORT wxControl
;
27 class WXDLLEXPORT wxCursor
;
28 class WXDLLEXPORT wxDC
;
29 class WXDLLEXPORT wxDIB
;
30 class WXDLLEXPORT wxIcon
;
31 class WXDLLEXPORT wxImage
;
32 class WXDLLEXPORT wxMask
;
33 class WXDLLEXPORT wxPalette
;
34 class WXDLLEXPORT wxPixelDataBase
;
36 // ----------------------------------------------------------------------------
37 // wxBitmap: a mono or colour bitmap
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxBitmap
: public wxGDIImage
43 // default ctor creates an invalid bitmap, you must Create() it later
44 wxBitmap() { Init(); }
47 wxBitmap(const wxBitmap
& bitmap
) { Init(); Ref(bitmap
); }
49 // Initialize with raw data
50 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
52 // Initialize with XPM data
53 wxBitmap(const char **data
) { CreateFromXpm(data
); }
54 wxBitmap(char **data
) { CreateFromXpm((const char **)data
); }
56 // Load a file or resource
57 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
59 // New constructor for generalised creation from data
60 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
62 // Create a new, uninitialized bitmap of the given size and depth (if it
63 // is omitted, will create a bitmap compatible with the display)
65 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
66 // taking a DC argument if you want to force using DDB in this case
67 wxBitmap(int width
, int height
, int depth
= -1);
69 // Create a bitmap compatible with the given DC
70 wxBitmap(int width
, int height
, const wxDC
& dc
);
73 // Convert from wxImage
74 wxBitmap(const wxImage
& image
, int depth
= -1)
75 { (void)CreateFromImage(image
, depth
); }
77 // Create a DDB compatible with the given DC from wxImage
78 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
79 { (void)CreateFromImage(image
, dc
); }
82 // we must have this, otherwise icons are silently copied into bitmaps using
83 // the copy ctor but the resulting bitmap is invalid!
84 wxBitmap(const wxIcon
& icon
) { Init(); CopyFromIcon(icon
); }
86 wxBitmap
& operator=(const wxBitmap
& bitmap
)
88 if ( m_refData
!= bitmap
.m_refData
)
93 wxBitmap
& operator=(const wxIcon
& icon
)
95 (void)CopyFromIcon(icon
);
100 wxBitmap
& operator=(const wxCursor
& cursor
)
102 (void)CopyFromCursor(cursor
);
110 wxImage
ConvertToImage() const;
111 #endif // wxUSE_IMAGE
113 // get the given part of bitmap
114 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
116 // copies the contents and mask of the given (colour) icon to the bitmap
117 bool CopyFromIcon(const wxIcon
& icon
);
119 // copies the contents and mask of the given cursor to the bitmap
120 bool CopyFromCursor(const wxCursor
& cursor
);
122 // copies from a device independent bitmap
123 bool CopyFromDIB(const wxDIB
& dib
);
125 virtual bool Create(int width
, int height
, int depth
= -1);
126 virtual bool Create(int width
, int height
, const wxDC
& dc
);
127 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
128 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
129 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
131 wxBitmapRefData
*GetBitmapData() const
132 { return (wxBitmapRefData
*)m_refData
; }
134 // raw bitmap access support functions
135 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
136 void UngetRawData(wxPixelDataBase
& data
);
139 wxPalette
* GetPalette() const;
140 void SetPalette(const wxPalette
& palette
);
141 #endif // wxUSE_PALETTE
143 wxMask
*GetMask() const;
144 void SetMask(wxMask
*mask
);
146 bool operator==(const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
147 bool operator!=(const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
149 // these functions are internal and shouldn't be used, they risk to
150 // disappear in the future
151 bool HasAlpha() const;
154 #if WXWIN_COMPATIBILITY_2_4
155 // these functions do nothing and are only there for backwards
157 wxDEPRECATED( int GetQuality() const );
158 wxDEPRECATED( void SetQuality(int quality
) );
159 #endif // WXWIN_COMPATIBILITY_2_4
161 #if WXWIN_COMPATIBILITY_2
162 void SetOk(bool isOk
);
163 #endif // WXWIN_COMPATIBILITY_2
165 #if WXWIN_COMPATIBILITY
167 wxPalette
*GetColourMap() const { return GetPalette(); }
168 void SetColourMap(wxPalette
*cmap
) { SetPalette(*cmap
); };
169 #endif // wxUSE_PALETTE
170 #endif // WXWIN_COMPATIBILITY
172 // implementation only from now on
173 // -------------------------------
176 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
177 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
180 void SetSelectedInto(wxDC
*dc
);
181 wxDC
*GetSelectedInto() const;
182 #endif // __WXDEBUG__
185 // common part of all ctors
188 virtual wxGDIImageRefData
*CreateData() const;
190 // creates the bitmap from XPM data, supposed to be called from ctor
191 bool CreateFromXpm(const char **bits
);
193 // creates an uninitialized bitmap, called from Create()s above
194 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
197 // creates the bitmap from wxImage, supposed to be called from ctor
198 bool CreateFromImage(const wxImage
& image
, int depth
);
200 // creates a DDB from wxImage, supposed to be called from ctor
201 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
203 // common part of the 2 methods above (hdc may be 0)
204 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
205 #endif // wxUSE_IMAGE
209 // common part of CopyFromIcon/CopyFromCursor for Win32
210 bool CopyFromIconOrCursor(const wxGDIImage
& icon
);
213 DECLARE_DYNAMIC_CLASS(wxBitmap
)
216 // ----------------------------------------------------------------------------
217 // wxMask: a mono bitmap used for drawing bitmaps transparently.
218 // ----------------------------------------------------------------------------
220 class WXDLLEXPORT wxMask
: public wxObject
225 // Construct a mask from a bitmap and a colour indicating the transparent
227 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
229 // Construct a mask from a bitmap and a palette index indicating the
231 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
233 // Construct a mask from a mono bitmap (copies the bitmap).
234 wxMask(const wxBitmap
& bitmap
);
236 // construct a mask from the givne bitmap handle
237 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
241 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
242 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
243 bool Create(const wxBitmap
& bitmap
);
246 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
247 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
250 WXHBITMAP m_maskBitmap
;
252 DECLARE_DYNAMIC_CLASS(wxMask
)
255 // ----------------------------------------------------------------------------
256 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
257 // ----------------------------------------------------------------------------
259 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
262 wxBitmapHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
263 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
264 : wxGDIImageHandler(name
, ext
, type
)
268 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
269 // old class which worked only with bitmaps
270 virtual bool Create(wxBitmap
*bitmap
,
273 int width
, int height
, int depth
= 1);
274 virtual bool LoadFile(wxBitmap
*bitmap
,
275 const wxString
& name
,
277 int desiredWidth
, int desiredHeight
);
278 virtual bool SaveFile(wxBitmap
*bitmap
,
279 const wxString
& name
,
281 const wxPalette
*palette
= NULL
);
283 virtual bool Create(wxGDIImage
*image
,
286 int width
, int height
, int depth
= 1);
287 virtual bool Load(wxGDIImage
*image
,
288 const wxString
& name
,
290 int desiredWidth
, int desiredHeight
);
291 virtual bool Save(wxGDIImage
*image
,
292 const wxString
& name
,
296 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)