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 WXDLLEXPORT wxBitmap
;
19 class WXDLLEXPORT wxBitmapHandler
;
20 class WXDLLEXPORT wxBitmapRefData
;
21 class WXDLLEXPORT wxControl
;
22 class WXDLLEXPORT wxCursor
;
23 class WXDLLEXPORT wxDC
;
25 class WXDLLEXPORT wxDIB
;
27 class WXDLLEXPORT wxIcon
;
28 class WXDLLEXPORT wxImage
;
29 class WXDLLEXPORT wxMask
;
30 class WXDLLEXPORT wxPalette
;
31 class WXDLLEXPORT wxPixelDataBase
;
33 // ----------------------------------------------------------------------------
34 // wxBitmap: a mono or colour bitmap
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxBitmap
: public wxGDIImage
40 // default ctor creates an invalid bitmap, you must Create() it later
43 // Initialize with raw data
44 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
46 // Initialize with XPM data
47 wxBitmap(const char* const* data
);
51 *this = wxBitmap(wx_const_cast(const char* const*, data
));
55 // Load a file or resource
56 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
58 // New constructor for generalised creation from data
59 wxBitmap(const void* data
, long type
, int width
, int height
, int depth
= 1);
61 // Create a new, uninitialized bitmap of the given size and depth (if it
62 // is omitted, will create a bitmap compatible with the display)
64 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
65 // taking a DC argument if you want to force using DDB in this case
66 wxBitmap(int width
, int height
, int depth
= -1);
68 // Create a bitmap compatible with the given DC
69 wxBitmap(int width
, int height
, const wxDC
& dc
);
72 // Convert from wxImage
73 wxBitmap(const wxImage
& image
, int depth
= -1)
74 { (void)CreateFromImage(image
, depth
); }
76 // Create a DDB compatible with the given DC from wxImage
77 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
78 { (void)CreateFromImage(image
, dc
); }
81 // we must have this, otherwise icons are silently copied into bitmaps using
82 // the copy ctor but the resulting bitmap is invalid!
83 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
85 wxBitmap
& operator=(const wxIcon
& icon
)
87 (void)CopyFromIcon(icon
);
92 wxBitmap
& operator=(const wxCursor
& cursor
)
94 (void)CopyFromCursor(cursor
);
102 wxImage
ConvertToImage() const;
103 #endif // wxUSE_IMAGE
105 // get the given part of bitmap
106 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
108 // copies the contents and mask of the given (colour) icon to the bitmap
109 bool CopyFromIcon(const wxIcon
& icon
);
111 // copies the contents and mask of the given cursor to the bitmap
112 bool CopyFromCursor(const wxCursor
& cursor
);
115 // copies from a device independent bitmap
116 bool CopyFromDIB(const wxDIB
& dib
);
119 virtual bool Create(int width
, int height
, int depth
= -1);
120 virtual bool Create(int width
, int height
, const wxDC
& dc
);
121 virtual bool Create(const void* data
, long type
, int width
, int height
, int depth
= 1);
122 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
123 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
125 wxBitmapRefData
*GetBitmapData() const
126 { return (wxBitmapRefData
*)m_refData
; }
128 // raw bitmap access support functions
129 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
130 void UngetRawData(wxPixelDataBase
& data
);
133 wxPalette
* GetPalette() const;
134 void SetPalette(const wxPalette
& palette
);
135 #endif // wxUSE_PALETTE
137 wxMask
*GetMask() const;
138 wxBitmap
GetMaskBitmap() const;
139 void SetMask(wxMask
*mask
);
141 // these functions are internal and shouldn't be used, they risk to
142 // disappear in the future
143 bool HasAlpha() const;
146 #if WXWIN_COMPATIBILITY_2_4
147 // these functions do nothing and are only there for backwards
149 wxDEPRECATED( int GetQuality() const );
150 wxDEPRECATED( void SetQuality(int quality
) );
151 #endif // WXWIN_COMPATIBILITY_2_4
153 // implementation only from now on
154 // -------------------------------
157 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
158 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
161 void SetSelectedInto(wxDC
*dc
);
162 wxDC
*GetSelectedInto() const;
163 #endif // __WXDEBUG__
166 virtual wxGDIImageRefData
*CreateData() const;
167 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
169 // creates an uninitialized bitmap, called from Create()s above
170 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
173 // creates the bitmap from wxImage, supposed to be called from ctor
174 bool CreateFromImage(const wxImage
& image
, int depth
);
176 // creates a DDB from wxImage, supposed to be called from ctor
177 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
179 // common part of the 2 methods above (hdc may be 0)
180 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
181 #endif // wxUSE_IMAGE
184 // common part of CopyFromIcon/CopyFromCursor for Win32
185 bool CopyFromIconOrCursor(const wxGDIImage
& icon
);
188 DECLARE_DYNAMIC_CLASS(wxBitmap
)
191 // ----------------------------------------------------------------------------
192 // wxMask: a mono bitmap used for drawing bitmaps transparently.
193 // ----------------------------------------------------------------------------
195 class WXDLLEXPORT wxMask
: public wxObject
201 wxMask(const wxMask
&mask
);
203 // Construct a mask from a bitmap and a colour indicating the transparent
205 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
207 // Construct a mask from a bitmap and a palette index indicating the
209 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
211 // Construct a mask from a mono bitmap (copies the bitmap).
212 wxMask(const wxBitmap
& bitmap
);
214 // construct a mask from the givne bitmap handle
215 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
219 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
220 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
221 bool Create(const wxBitmap
& bitmap
);
224 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
225 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
228 WXHBITMAP m_maskBitmap
;
230 DECLARE_DYNAMIC_CLASS(wxMask
)
233 // ----------------------------------------------------------------------------
234 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
235 // ----------------------------------------------------------------------------
237 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
240 wxBitmapHandler() { }
241 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
242 : wxGDIImageHandler(name
, ext
, type
)
246 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
247 // old class which worked only with bitmaps
248 virtual bool Create(wxBitmap
*bitmap
,
251 int width
, int height
, int depth
= 1);
252 virtual bool LoadFile(wxBitmap
*bitmap
,
253 const wxString
& name
,
255 int desiredWidth
, int desiredHeight
);
256 virtual bool SaveFile(wxBitmap
*bitmap
,
257 const wxString
& name
,
259 const wxPalette
*palette
= NULL
);
261 virtual bool Create(wxGDIImage
*image
,
264 int width
, int height
, int depth
= 1);
265 virtual bool Load(wxGDIImage
*image
,
266 const wxString
& name
,
268 int desiredWidth
, int desiredHeight
);
269 virtual bool Save(wxGDIImage
*image
,
270 const wxString
& name
,
274 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)