]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/bitmap.h
No changes, just remove unnecessary wxPickerBase::OnSize().
[wxWidgets.git] / include / wx / msw / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #include "wx/msw/gdiimage.h"
16 #include "wx/palette.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxBitmap;
19 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
20 class WXDLLIMPEXP_FWD_CORE wxBitmapRefData;
21 class WXDLLIMPEXP_FWD_CORE wxControl;
22 class WXDLLIMPEXP_FWD_CORE wxCursor;
23 class WXDLLIMPEXP_FWD_CORE wxDC;
24 #if wxUSE_WXDIB
25 class WXDLLIMPEXP_FWD_CORE wxDIB;
26 #endif
27 class WXDLLIMPEXP_FWD_CORE wxIcon;
28 class WXDLLIMPEXP_FWD_CORE wxMask;
29 class WXDLLIMPEXP_FWD_CORE wxPalette;
30 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
31
32 // What kind of transparency should a bitmap copied from an icon or cursor
33 // have?
34 enum wxBitmapTransparency
35 {
36 wxBitmapTransparency_Auto, // default: copy alpha if the source has it
37 wxBitmapTransparency_None, // never create alpha
38 wxBitmapTransparency_Always // always use alpha
39 };
40
41 // ----------------------------------------------------------------------------
42 // wxBitmap: a mono or colour bitmap
43 // NOTE: for wxMSW we don't use the wxBitmapBase base class declared in bitmap.h!
44 // ----------------------------------------------------------------------------
45
46 class WXDLLIMPEXP_CORE wxBitmap : public wxGDIImage
47 {
48 public:
49 // default ctor creates an invalid bitmap, you must Create() it later
50 wxBitmap() { }
51
52 // Initialize with raw data
53 wxBitmap(const char bits[], int width, int height, int depth = 1);
54
55 // Initialize with XPM data
56 wxBitmap(const char* const* data);
57 #ifdef wxNEEDS_CHARPP
58 wxBitmap(char** data)
59 {
60 *this = wxBitmap(const_cast<const char* const*>(data));
61 }
62 #endif
63
64 // Load a file or resource
65 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
66
67 // New constructor for generalised creation from data
68 wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
69
70 // Create a new, uninitialized bitmap of the given size and depth (if it
71 // is omitted, will create a bitmap compatible with the display)
72 //
73 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
74 // taking a DC argument if you want to force using DDB in this case
75 wxBitmap(int width, int height, int depth = -1) { (void)Create(width, height, depth); }
76 wxBitmap(const wxSize& sz, int depth = -1) { (void)Create(sz, depth); }
77
78 // Create a bitmap compatible with the given DC
79 wxBitmap(int width, int height, const wxDC& dc);
80
81 #if wxUSE_IMAGE
82 // Convert from wxImage
83 wxBitmap(const wxImage& image, int depth = -1)
84 { (void)CreateFromImage(image, depth); }
85
86 // Create a DDB compatible with the given DC from wxImage
87 wxBitmap(const wxImage& image, const wxDC& dc)
88 { (void)CreateFromImage(image, dc); }
89 #endif // wxUSE_IMAGE
90
91 // we must have this, otherwise icons are silently copied into bitmaps using
92 // the copy ctor but the resulting bitmap is invalid!
93 wxBitmap(const wxIcon& icon,
94 wxBitmapTransparency transp = wxBitmapTransparency_Auto)
95 {
96 CopyFromIcon(icon, transp);
97 }
98
99 wxBitmap& operator=(const wxIcon& icon)
100 {
101 (void)CopyFromIcon(icon);
102
103 return *this;
104 }
105
106 wxBitmap& operator=(const wxCursor& cursor)
107 {
108 (void)CopyFromCursor(cursor);
109
110 return *this;
111 }
112
113 virtual ~wxBitmap();
114
115 #if wxUSE_IMAGE
116 wxImage ConvertToImage() const;
117 wxBitmap ConvertToDisabled(unsigned char brightness = 255) const;
118 #endif // wxUSE_IMAGE
119
120 // get the given part of bitmap
121 wxBitmap GetSubBitmap( const wxRect& rect ) const;
122
123 // NB: This should not be called from user code. It is for wx internal
124 // use only.
125 wxBitmap GetSubBitmapOfHDC( const wxRect& rect, WXHDC hdc ) const;
126
127 // copies the contents and mask of the given (colour) icon to the bitmap
128 bool CopyFromIcon(const wxIcon& icon,
129 wxBitmapTransparency transp = wxBitmapTransparency_Auto);
130
131 // copies the contents and mask of the given cursor to the bitmap
132 bool CopyFromCursor(const wxCursor& cursor,
133 wxBitmapTransparency transp = wxBitmapTransparency_Auto);
134
135 #if wxUSE_WXDIB
136 // copies from a device independent bitmap
137 bool CopyFromDIB(const wxDIB& dib);
138 #endif
139
140 virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
141 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
142 { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
143
144 virtual bool Create(int width, int height, const wxDC& dc);
145 virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
146 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
147 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
148
149 wxBitmapRefData *GetBitmapData() const
150 { return (wxBitmapRefData *)m_refData; }
151
152 // raw bitmap access support functions
153 void *GetRawData(wxPixelDataBase& data, int bpp);
154 void UngetRawData(wxPixelDataBase& data);
155
156 #if wxUSE_PALETTE
157 wxPalette* GetPalette() const;
158 void SetPalette(const wxPalette& palette);
159 #endif // wxUSE_PALETTE
160
161 wxMask *GetMask() const;
162 wxBitmap GetMaskBitmap() const;
163 void SetMask(wxMask *mask);
164
165 // these functions are internal and shouldn't be used, they risk to
166 // disappear in the future
167 bool HasAlpha() const;
168 void UseAlpha();
169
170 // implementation only from now on
171 // -------------------------------
172
173 public:
174 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
175 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
176
177 void SetSelectedInto(wxDC *dc);
178 wxDC *GetSelectedInto() const;
179
180 protected:
181 virtual wxGDIImageRefData *CreateData() const;
182 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
183
184 // creates an uninitialized bitmap, called from Create()s above
185 bool DoCreate(int w, int h, int depth, WXHDC hdc);
186
187 #if wxUSE_IMAGE
188 // creates the bitmap from wxImage, supposed to be called from ctor
189 bool CreateFromImage(const wxImage& image, int depth);
190
191 // creates a DDB from wxImage, supposed to be called from ctor
192 bool CreateFromImage(const wxImage& image, const wxDC& dc);
193
194 // common part of the 2 methods above (hdc may be 0)
195 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
196 #endif // wxUSE_IMAGE
197
198 private:
199 // common part of CopyFromIcon/CopyFromCursor for Win32
200 bool
201 CopyFromIconOrCursor(const wxGDIImage& icon,
202 wxBitmapTransparency transp = wxBitmapTransparency_Auto);
203
204
205 DECLARE_DYNAMIC_CLASS(wxBitmap)
206 };
207
208 // ----------------------------------------------------------------------------
209 // wxMask: a mono bitmap used for drawing bitmaps transparently.
210 // ----------------------------------------------------------------------------
211
212 class WXDLLIMPEXP_CORE wxMask : public wxObject
213 {
214 public:
215 wxMask();
216
217 // Copy constructor
218 wxMask(const wxMask &mask);
219
220 // Construct a mask from a bitmap and a colour indicating the transparent
221 // area
222 wxMask(const wxBitmap& bitmap, const wxColour& colour);
223
224 // Construct a mask from a bitmap and a palette index indicating the
225 // transparent area
226 wxMask(const wxBitmap& bitmap, int paletteIndex);
227
228 // Construct a mask from a mono bitmap (copies the bitmap).
229 wxMask(const wxBitmap& bitmap);
230
231 // construct a mask from the givne bitmap handle
232 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
233
234 virtual ~wxMask();
235
236 bool Create(const wxBitmap& bitmap, const wxColour& colour);
237 bool Create(const wxBitmap& bitmap, int paletteIndex);
238 bool Create(const wxBitmap& bitmap);
239
240 // Implementation
241 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
242 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
243
244 protected:
245 WXHBITMAP m_maskBitmap;
246
247 DECLARE_DYNAMIC_CLASS(wxMask)
248 };
249
250
251 // ----------------------------------------------------------------------------
252 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
253 // NOTE: for wxMSW we don't use the wxBitmapHandler class declared in bitmap.h!
254 // ----------------------------------------------------------------------------
255
256 class WXDLLIMPEXP_CORE wxBitmapHandler : public wxGDIImageHandler
257 {
258 public:
259 wxBitmapHandler() { }
260 wxBitmapHandler(const wxString& name, const wxString& ext, wxBitmapType type)
261 : wxGDIImageHandler(name, ext, type) { }
262
263 // implement wxGDIImageHandler's pure virtuals:
264
265 virtual bool Create(wxGDIImage *image,
266 const void* data,
267 wxBitmapType type,
268 int width, int height, int depth = 1);
269 virtual bool Load(wxGDIImage *image,
270 const wxString& name,
271 wxBitmapType type,
272 int desiredWidth, int desiredHeight);
273 virtual bool Save(const wxGDIImage *image,
274 const wxString& name,
275 wxBitmapType type) const;
276
277
278 // make wxBitmapHandler compatible with the wxBitmapHandler interface
279 // declared in bitmap.h, even if it's derived from wxGDIImageHandler:
280
281 virtual bool Create(wxBitmap *bitmap,
282 const void* data,
283 wxBitmapType type,
284 int width, int height, int depth = 1);
285 virtual bool LoadFile(wxBitmap *bitmap,
286 const wxString& name,
287 wxBitmapType type,
288 int desiredWidth, int desiredHeight);
289 virtual bool SaveFile(const wxBitmap *bitmap,
290 const wxString& name,
291 wxBitmapType type,
292 const wxPalette *palette = NULL) const;
293
294 private:
295 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
296 };
297
298 #endif
299 // _WX_BITMAP_H_