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
;
30 class WXDLLEXPORT wxDIB
;
32 class WXDLLEXPORT wxIcon
;
33 class WXDLLEXPORT wxImage
;
34 class WXDLLEXPORT wxMask
;
35 class WXDLLEXPORT wxPalette
;
36 class WXDLLEXPORT wxPixelDataBase
;
38 // ----------------------------------------------------------------------------
39 // wxBitmap: a mono or colour bitmap
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxBitmap
: public wxGDIImage
45 // default ctor creates an invalid bitmap, you must Create() it later
46 wxBitmap() { Init(); }
49 wxBitmap(const wxBitmap
& bitmap
) { Init(); Ref(bitmap
); }
51 // Initialize with raw data
52 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
54 // Initialize with XPM data
55 wxBitmap(const char **data
) { CreateFromXpm(data
); }
56 wxBitmap(char **data
) { CreateFromXpm((const char **)data
); }
58 // Load a file or resource
59 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
61 // New constructor for generalised creation from data
62 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
64 // Create a new, uninitialized bitmap of the given size and depth (if it
65 // is omitted, will create a bitmap compatible with the display)
67 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
68 // taking a DC argument if you want to force using DDB in this case
69 wxBitmap(int width
, int height
, int depth
= -1);
71 // Create a bitmap compatible with the given DC
72 wxBitmap(int width
, int height
, const wxDC
& dc
);
75 // Convert from wxImage
76 wxBitmap(const wxImage
& image
, int depth
= -1)
77 { (void)CreateFromImage(image
, depth
); }
79 // Create a DDB compatible with the given DC from wxImage
80 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
81 { (void)CreateFromImage(image
, dc
); }
84 // we must have this, otherwise icons are silently copied into bitmaps using
85 // the copy ctor but the resulting bitmap is invalid!
86 wxBitmap(const wxIcon
& icon
) { Init(); CopyFromIcon(icon
); }
88 wxBitmap
& operator=(const wxBitmap
& bitmap
)
90 if ( m_refData
!= bitmap
.m_refData
)
95 wxBitmap
& operator=(const wxIcon
& icon
)
97 (void)CopyFromIcon(icon
);
102 wxBitmap
& operator=(const wxCursor
& cursor
)
104 (void)CopyFromCursor(cursor
);
112 wxImage
ConvertToImage() const;
113 #endif // wxUSE_IMAGE
115 // get the given part of bitmap
116 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
118 // copies the contents and mask of the given (colour) icon to the bitmap
119 bool CopyFromIcon(const wxIcon
& icon
);
121 // copies the contents and mask of the given cursor to the bitmap
122 bool CopyFromCursor(const wxCursor
& cursor
);
125 // copies from a device independent bitmap
126 bool CopyFromDIB(const wxDIB
& dib
);
129 virtual bool Create(int width
, int height
, int depth
= -1);
130 virtual bool Create(int width
, int height
, const wxDC
& dc
);
131 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
132 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
133 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
135 wxBitmapRefData
*GetBitmapData() const
136 { return (wxBitmapRefData
*)m_refData
; }
138 // raw bitmap access support functions
139 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
140 void UngetRawData(wxPixelDataBase
& data
);
143 wxPalette
* GetPalette() const;
144 void SetPalette(const wxPalette
& palette
);
145 #endif // wxUSE_PALETTE
147 wxMask
*GetMask() const;
148 void SetMask(wxMask
*mask
);
150 bool operator==(const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
151 bool operator!=(const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
153 // these functions are internal and shouldn't be used, they risk to
154 // disappear in the future
155 bool HasAlpha() const;
158 #if WXWIN_COMPATIBILITY_2_4
159 // these functions do nothing and are only there for backwards
161 wxDEPRECATED( int GetQuality() const );
162 wxDEPRECATED( void SetQuality(int quality
) );
163 #endif // WXWIN_COMPATIBILITY_2_4
165 #if WXWIN_COMPATIBILITY_2
166 void SetOk(bool isOk
);
167 #endif // WXWIN_COMPATIBILITY_2
169 #if WXWIN_COMPATIBILITY
171 wxPalette
*GetColourMap() const { return GetPalette(); }
172 void SetColourMap(wxPalette
*cmap
) { SetPalette(*cmap
); };
173 #endif // wxUSE_PALETTE
174 #endif // WXWIN_COMPATIBILITY
176 // implementation only from now on
177 // -------------------------------
180 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
181 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
184 void SetSelectedInto(wxDC
*dc
);
185 wxDC
*GetSelectedInto() const;
186 #endif // __WXDEBUG__
189 // common part of all ctors
192 virtual wxGDIImageRefData
*CreateData() const;
194 // creates the bitmap from XPM data, supposed to be called from ctor
195 bool CreateFromXpm(const char **bits
);
197 // creates an uninitialized bitmap, called from Create()s above
198 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
201 // creates the bitmap from wxImage, supposed to be called from ctor
202 bool CreateFromImage(const wxImage
& image
, int depth
);
204 // creates a DDB from wxImage, supposed to be called from ctor
205 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
207 // common part of the 2 methods above (hdc may be 0)
208 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
209 #endif // wxUSE_IMAGE
213 // common part of CopyFromIcon/CopyFromCursor for Win32
214 bool CopyFromIconOrCursor(const wxGDIImage
& icon
);
217 DECLARE_DYNAMIC_CLASS(wxBitmap
)
220 // ----------------------------------------------------------------------------
221 // wxMask: a mono bitmap used for drawing bitmaps transparently.
222 // ----------------------------------------------------------------------------
224 class WXDLLEXPORT wxMask
: public wxObject
229 // Construct a mask from a bitmap and a colour indicating the transparent
231 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
233 // Construct a mask from a bitmap and a palette index indicating the
235 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
237 // Construct a mask from a mono bitmap (copies the bitmap).
238 wxMask(const wxBitmap
& bitmap
);
240 // construct a mask from the givne bitmap handle
241 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
245 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
246 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
247 bool Create(const wxBitmap
& bitmap
);
250 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
251 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
254 WXHBITMAP m_maskBitmap
;
256 DECLARE_DYNAMIC_CLASS(wxMask
)
259 // ----------------------------------------------------------------------------
260 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
261 // ----------------------------------------------------------------------------
263 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
266 wxBitmapHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
267 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
268 : wxGDIImageHandler(name
, ext
, type
)
272 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
273 // old class which worked only with bitmaps
274 virtual bool Create(wxBitmap
*bitmap
,
277 int width
, int height
, int depth
= 1);
278 virtual bool LoadFile(wxBitmap
*bitmap
,
279 const wxString
& name
,
281 int desiredWidth
, int desiredHeight
);
282 virtual bool SaveFile(wxBitmap
*bitmap
,
283 const wxString
& name
,
285 const wxPalette
*palette
= NULL
);
287 virtual bool Create(wxGDIImage
*image
,
290 int width
, int height
, int depth
= 1);
291 virtual bool Load(wxGDIImage
*image
,
292 const wxString
& name
,
294 int desiredWidth
, int desiredHeight
);
295 virtual bool Save(wxGDIImage
*image
,
296 const wxString
& name
,
300 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)