]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/bitmap.h
replacing old core graphics with new graphics context implementation
[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 WXDLLEXPORT wxBitmap;
19 class WXDLLEXPORT wxBitmapHandler;
20 class WXDLLEXPORT wxBitmapRefData;
21 class WXDLLEXPORT wxControl;
22 class WXDLLEXPORT wxCursor;
23 class WXDLLEXPORT wxDC;
24 #if wxUSE_WXDIB
25 class WXDLLEXPORT wxDIB;
26 #endif
27 class WXDLLEXPORT wxIcon;
28 class WXDLLEXPORT wxImage;
29 class WXDLLEXPORT wxMask;
30 class WXDLLEXPORT wxPalette;
31 class WXDLLEXPORT wxPixelDataBase;
32
33 // ----------------------------------------------------------------------------
34 // wxBitmap: a mono or colour bitmap
35 // ----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxBitmap : public wxGDIImage
38 {
39 public:
40 // default ctor creates an invalid bitmap, you must Create() it later
41 wxBitmap() { }
42
43 // Initialize with raw data
44 wxBitmap(const char bits[], int width, int height, int depth = 1);
45
46 // Initialize with XPM data
47 wxBitmap(const char* const* data);
48
49 // Load a file or resource
50 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
51
52 // New constructor for generalised creation from data
53 wxBitmap(const void* data, long type, int width, int height, int depth = 1);
54
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)
57 //
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);
61
62 // Create a bitmap compatible with the given DC
63 wxBitmap(int width, int height, const wxDC& dc);
64
65 #if wxUSE_IMAGE
66 // Convert from wxImage
67 wxBitmap(const wxImage& image, int depth = -1)
68 { (void)CreateFromImage(image, depth); }
69
70 // Create a DDB compatible with the given DC from wxImage
71 wxBitmap(const wxImage& image, const wxDC& dc)
72 { (void)CreateFromImage(image, dc); }
73 #endif // wxUSE_IMAGE
74
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); }
78
79 wxBitmap& operator=(const wxIcon& icon)
80 {
81 (void)CopyFromIcon(icon);
82
83 return *this;
84 }
85
86 wxBitmap& operator=(const wxCursor& cursor)
87 {
88 (void)CopyFromCursor(cursor);
89
90 return *this;
91 }
92
93 virtual ~wxBitmap();
94
95 #if wxUSE_IMAGE
96 wxImage ConvertToImage() const;
97 #endif // wxUSE_IMAGE
98
99 // get the given part of bitmap
100 wxBitmap GetSubBitmap( const wxRect& rect ) const;
101
102 // copies the contents and mask of the given (colour) icon to the bitmap
103 bool CopyFromIcon(const wxIcon& icon);
104
105 // copies the contents and mask of the given cursor to the bitmap
106 bool CopyFromCursor(const wxCursor& cursor);
107
108 #if wxUSE_WXDIB
109 // copies from a device independent bitmap
110 bool CopyFromDIB(const wxDIB& dib);
111 #endif
112
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);
118
119 wxBitmapRefData *GetBitmapData() const
120 { return (wxBitmapRefData *)m_refData; }
121
122 // raw bitmap access support functions
123 void *GetRawData(wxPixelDataBase& data, int bpp);
124 void UngetRawData(wxPixelDataBase& data);
125
126 #if wxUSE_PALETTE
127 wxPalette* GetPalette() const;
128 void SetPalette(const wxPalette& palette);
129 #endif // wxUSE_PALETTE
130
131 wxMask *GetMask() const;
132 wxBitmap GetMaskBitmap() const;
133 void SetMask(wxMask *mask);
134
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; }
137
138 // these functions are internal and shouldn't be used, they risk to
139 // disappear in the future
140 bool HasAlpha() const;
141 void UseAlpha();
142
143 #if WXWIN_COMPATIBILITY_2_4
144 // these functions do nothing and are only there for backwards
145 // compatibility
146 wxDEPRECATED( int GetQuality() const );
147 wxDEPRECATED( void SetQuality(int quality) );
148 #endif // WXWIN_COMPATIBILITY_2_4
149
150 // implementation only from now on
151 // -------------------------------
152
153 public:
154 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
155 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
156
157 #ifdef __WXDEBUG__
158 void SetSelectedInto(wxDC *dc);
159 wxDC *GetSelectedInto() const;
160 #endif // __WXDEBUG__
161
162 protected:
163 virtual wxGDIImageRefData *CreateData() const;
164 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
165
166 // creates an uninitialized bitmap, called from Create()s above
167 bool DoCreate(int w, int h, int depth, WXHDC hdc);
168
169 #if wxUSE_IMAGE
170 // creates the bitmap from wxImage, supposed to be called from ctor
171 bool CreateFromImage(const wxImage& image, int depth);
172
173 // creates a DDB from wxImage, supposed to be called from ctor
174 bool CreateFromImage(const wxImage& image, const wxDC& dc);
175
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
179
180 private:
181 // common part of CopyFromIcon/CopyFromCursor for Win32
182 bool CopyFromIconOrCursor(const wxGDIImage& icon);
183
184
185 DECLARE_DYNAMIC_CLASS(wxBitmap)
186 };
187
188 // ----------------------------------------------------------------------------
189 // wxMask: a mono bitmap used for drawing bitmaps transparently.
190 // ----------------------------------------------------------------------------
191
192 class WXDLLEXPORT wxMask : public wxObject
193 {
194 public:
195 wxMask();
196
197 // Construct a mask from a bitmap and a colour indicating the transparent
198 // area
199 wxMask(const wxBitmap& bitmap, const wxColour& colour);
200
201 // Construct a mask from a bitmap and a palette index indicating the
202 // transparent area
203 wxMask(const wxBitmap& bitmap, int paletteIndex);
204
205 // Construct a mask from a mono bitmap (copies the bitmap).
206 wxMask(const wxBitmap& bitmap);
207
208 // construct a mask from the givne bitmap handle
209 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
210
211 virtual ~wxMask();
212
213 bool Create(const wxBitmap& bitmap, const wxColour& colour);
214 bool Create(const wxBitmap& bitmap, int paletteIndex);
215 bool Create(const wxBitmap& bitmap);
216
217 // Implementation
218 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
219 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
220
221 protected:
222 WXHBITMAP m_maskBitmap;
223
224 DECLARE_DYNAMIC_CLASS(wxMask)
225 };
226
227 // ----------------------------------------------------------------------------
228 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
229 // ----------------------------------------------------------------------------
230
231 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
232 {
233 public:
234 wxBitmapHandler() { }
235 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
236 : wxGDIImageHandler(name, ext, type)
237 {
238 }
239
240 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
241 // old class which worked only with bitmaps
242 virtual bool Create(wxBitmap *bitmap,
243 const void* data,
244 long flags,
245 int width, int height, int depth = 1);
246 virtual bool LoadFile(wxBitmap *bitmap,
247 const wxString& name,
248 long flags,
249 int desiredWidth, int desiredHeight);
250 virtual bool SaveFile(wxBitmap *bitmap,
251 const wxString& name,
252 int type,
253 const wxPalette *palette = NULL);
254
255 virtual bool Create(wxGDIImage *image,
256 const void* data,
257 long flags,
258 int width, int height, int depth = 1);
259 virtual bool Load(wxGDIImage *image,
260 const wxString& name,
261 long flags,
262 int desiredWidth, int desiredHeight);
263 virtual bool Save(wxGDIImage *image,
264 const wxString& name,
265 int type);
266
267 private:
268 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
269 };
270
271 #endif
272 // _WX_BITMAP_H_