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
);
49 // Load a file or resource
50 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
52 // New constructor for generalised creation from data
53 wxBitmap(const void* data
, long type
, int width
, int height
, int depth
= 1);
55 // Create a new, uninitialized bitmap of the given size and depth (if it
56 // is omitted, will create a bitmap compatible with the display)
58 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
59 // taking a DC argument if you want to force using DDB in this case
60 wxBitmap(int width
, int height
, int depth
= -1);
62 // Create a bitmap compatible with the given DC
63 wxBitmap(int width
, int height
, const wxDC
& dc
);
66 // Convert from wxImage
67 wxBitmap(const wxImage
& image
, int depth
= -1)
68 { (void)CreateFromImage(image
, depth
); }
70 // Create a DDB compatible with the given DC from wxImage
71 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
72 { (void)CreateFromImage(image
, dc
); }
75 // we must have this, otherwise icons are silently copied into bitmaps using
76 // the copy ctor but the resulting bitmap is invalid!
77 wxBitmap(const wxIcon
& icon
) { CopyFromIcon(icon
); }
79 wxBitmap
& operator=(const wxIcon
& icon
)
81 (void)CopyFromIcon(icon
);
86 wxBitmap
& operator=(const wxCursor
& cursor
)
88 (void)CopyFromCursor(cursor
);
96 wxImage
ConvertToImage() const;
99 // get the given part of bitmap
100 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
102 // copies the contents and mask of the given (colour) icon to the bitmap
103 bool CopyFromIcon(const wxIcon
& icon
);
105 // copies the contents and mask of the given cursor to the bitmap
106 bool CopyFromCursor(const wxCursor
& cursor
);
109 // copies from a device independent bitmap
110 bool CopyFromDIB(const wxDIB
& dib
);
113 virtual bool Create(int width
, int height
, int depth
= -1);
114 virtual bool Create(int width
, int height
, const wxDC
& dc
);
115 virtual bool Create(const void* data
, long type
, int width
, int height
, int depth
= 1);
116 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
117 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
119 wxBitmapRefData
*GetBitmapData() const
120 { return (wxBitmapRefData
*)m_refData
; }
122 // raw bitmap access support functions
123 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
124 void UngetRawData(wxPixelDataBase
& data
);
127 wxPalette
* GetPalette() const;
128 void SetPalette(const wxPalette
& palette
);
129 #endif // wxUSE_PALETTE
131 wxMask
*GetMask() const;
132 wxBitmap
GetMaskBitmap() const;
133 void SetMask(wxMask
*mask
);
135 bool operator==(const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
136 bool operator!=(const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
138 // these functions are internal and shouldn't be used, they risk to
139 // disappear in the future
140 bool HasAlpha() const;
143 #if WXWIN_COMPATIBILITY_2_4
144 // these functions do nothing and are only there for backwards
146 wxDEPRECATED( int GetQuality() const );
147 wxDEPRECATED( void SetQuality(int quality
) );
148 #endif // WXWIN_COMPATIBILITY_2_4
150 // implementation only from now on
151 // -------------------------------
154 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
155 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
158 void SetSelectedInto(wxDC
*dc
);
159 wxDC
*GetSelectedInto() const;
160 #endif // __WXDEBUG__
163 virtual wxGDIImageRefData
*CreateData() const;
164 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
166 // creates an uninitialized bitmap, called from Create()s above
167 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
170 // creates the bitmap from wxImage, supposed to be called from ctor
171 bool CreateFromImage(const wxImage
& image
, int depth
);
173 // creates a DDB from wxImage, supposed to be called from ctor
174 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
176 // common part of the 2 methods above (hdc may be 0)
177 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
178 #endif // wxUSE_IMAGE
181 // common part of CopyFromIcon/CopyFromCursor for Win32
182 bool CopyFromIconOrCursor(const wxGDIImage
& icon
);
185 DECLARE_DYNAMIC_CLASS(wxBitmap
)
188 // ----------------------------------------------------------------------------
189 // wxMask: a mono bitmap used for drawing bitmaps transparently.
190 // ----------------------------------------------------------------------------
192 class WXDLLEXPORT wxMask
: public wxObject
197 // Construct a mask from a bitmap and a colour indicating the transparent
199 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
201 // Construct a mask from a bitmap and a palette index indicating the
203 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
205 // Construct a mask from a mono bitmap (copies the bitmap).
206 wxMask(const wxBitmap
& bitmap
);
208 // construct a mask from the givne bitmap handle
209 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
213 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
214 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
215 bool Create(const wxBitmap
& bitmap
);
218 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
219 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
222 WXHBITMAP m_maskBitmap
;
224 DECLARE_DYNAMIC_CLASS(wxMask
)
227 // ----------------------------------------------------------------------------
228 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
229 // ----------------------------------------------------------------------------
231 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
234 wxBitmapHandler() { }
235 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
236 : wxGDIImageHandler(name
, ext
, type
)
240 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
241 // old class which worked only with bitmaps
242 virtual bool Create(wxBitmap
*bitmap
,
245 int width
, int height
, int depth
= 1);
246 virtual bool LoadFile(wxBitmap
*bitmap
,
247 const wxString
& name
,
249 int desiredWidth
, int desiredHeight
);
250 virtual bool SaveFile(wxBitmap
*bitmap
,
251 const wxString
& name
,
253 const wxPalette
*palette
= NULL
);
255 virtual bool Create(wxGDIImage
*image
,
258 int width
, int height
, int depth
= 1);
259 virtual bool Load(wxGDIImage
*image
,
260 const wxString
& name
,
262 int desiredWidth
, int desiredHeight
);
263 virtual bool Save(wxGDIImage
*image
,
264 const wxString
& name
,
268 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)