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
);
48 #if defined(__BORLANDC__) || (defined (__GNUC__) && __GNUC__ < 3)
49 // needed for Borland 5.5
52 *this = wxBitmap(wx_const_cast(const char* const*, 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(const 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
) { CopyFromIcon(icon
); }
86 wxBitmap
& operator=(const wxIcon
& icon
)
88 (void)CopyFromIcon(icon
);
93 wxBitmap
& operator=(const wxCursor
& cursor
)
95 (void)CopyFromCursor(cursor
);
103 wxImage
ConvertToImage() const;
104 #endif // wxUSE_IMAGE
106 // get the given part of bitmap
107 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
109 // copies the contents and mask of the given (colour) icon to the bitmap
110 bool CopyFromIcon(const wxIcon
& icon
);
112 // copies the contents and mask of the given cursor to the bitmap
113 bool CopyFromCursor(const wxCursor
& cursor
);
116 // copies from a device independent bitmap
117 bool CopyFromDIB(const wxDIB
& dib
);
120 virtual bool Create(int width
, int height
, int depth
= -1);
121 virtual bool Create(int width
, int height
, const wxDC
& dc
);
122 virtual bool Create(const void* data
, long type
, int width
, int height
, int depth
= 1);
123 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
124 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
126 wxBitmapRefData
*GetBitmapData() const
127 { return (wxBitmapRefData
*)m_refData
; }
129 // raw bitmap access support functions
130 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
131 void UngetRawData(wxPixelDataBase
& data
);
134 wxPalette
* GetPalette() const;
135 void SetPalette(const wxPalette
& palette
);
136 #endif // wxUSE_PALETTE
138 wxMask
*GetMask() const;
139 wxBitmap
GetMaskBitmap() const;
140 void SetMask(wxMask
*mask
);
142 // these functions are internal and shouldn't be used, they risk to
143 // disappear in the future
144 bool HasAlpha() const;
147 #if WXWIN_COMPATIBILITY_2_4
148 // these functions do nothing and are only there for backwards
150 wxDEPRECATED( int GetQuality() const );
151 wxDEPRECATED( void SetQuality(int quality
) );
152 #endif // WXWIN_COMPATIBILITY_2_4
154 // implementation only from now on
155 // -------------------------------
158 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
159 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
162 void SetSelectedInto(wxDC
*dc
);
163 wxDC
*GetSelectedInto() const;
164 #endif // __WXDEBUG__
167 virtual wxGDIImageRefData
*CreateData() const;
168 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
170 // creates an uninitialized bitmap, called from Create()s above
171 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
174 // creates the bitmap from wxImage, supposed to be called from ctor
175 bool CreateFromImage(const wxImage
& image
, int depth
);
177 // creates a DDB from wxImage, supposed to be called from ctor
178 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
180 // common part of the 2 methods above (hdc may be 0)
181 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
182 #endif // wxUSE_IMAGE
185 // common part of CopyFromIcon/CopyFromCursor for Win32
186 bool CopyFromIconOrCursor(const wxGDIImage
& icon
);
189 DECLARE_DYNAMIC_CLASS(wxBitmap
)
192 // ----------------------------------------------------------------------------
193 // wxMask: a mono bitmap used for drawing bitmaps transparently.
194 // ----------------------------------------------------------------------------
196 class WXDLLEXPORT wxMask
: public wxObject
201 // Construct a mask from a bitmap and a colour indicating the transparent
203 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
205 // Construct a mask from a bitmap and a palette index indicating the
207 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
209 // Construct a mask from a mono bitmap (copies the bitmap).
210 wxMask(const wxBitmap
& bitmap
);
212 // construct a mask from the givne bitmap handle
213 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
217 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
218 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
219 bool Create(const wxBitmap
& bitmap
);
222 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
223 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
226 WXHBITMAP m_maskBitmap
;
228 DECLARE_DYNAMIC_CLASS(wxMask
)
231 // ----------------------------------------------------------------------------
232 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
233 // ----------------------------------------------------------------------------
235 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
238 wxBitmapHandler() { }
239 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
240 : wxGDIImageHandler(name
, ext
, type
)
244 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
245 // old class which worked only with bitmaps
246 virtual bool Create(wxBitmap
*bitmap
,
249 int width
, int height
, int depth
= 1);
250 virtual bool LoadFile(wxBitmap
*bitmap
,
251 const wxString
& name
,
253 int desiredWidth
, int desiredHeight
);
254 virtual bool SaveFile(wxBitmap
*bitmap
,
255 const wxString
& name
,
257 const wxPalette
*palette
= NULL
);
259 virtual bool Create(wxGDIImage
*image
,
262 int width
, int height
, int depth
= 1);
263 virtual bool Load(wxGDIImage
*image
,
264 const wxString
& name
,
266 int desiredWidth
, int desiredHeight
);
267 virtual bool Save(wxGDIImage
*image
,
268 const wxString
& name
,
272 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)