update to make digitalmars compile
[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 #ifdef __GNUG__
16 #pragma interface "bitmap.h"
17 #endif
18
19 #include "wx/msw/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
22
23 class WXDLLEXPORT wxBitmap;
24 class WXDLLEXPORT wxBitmapHandler;
25 class WXDLLEXPORT wxBitmapRefData;
26 class WXDLLEXPORT wxControl;
27 class WXDLLEXPORT wxCursor;
28 class WXDLLEXPORT wxDC;
29 class WXDLLEXPORT wxDIB;
30 class WXDLLEXPORT wxIcon;
31 class WXDLLEXPORT wxImage;
32 class WXDLLEXPORT wxMask;
33 class WXDLLEXPORT wxPalette;
34 class WXDLLEXPORT wxRawBitmapData;
35
36 // ----------------------------------------------------------------------------
37 // wxBitmap: a mono or colour bitmap
38 // ----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxBitmap : public wxGDIImage
41 {
42 public:
43 // default ctor creates an invalid bitmap, you must Create() it later
44 wxBitmap() { Init(); }
45
46 // Copy constructors
47 wxBitmap(const wxBitmap& bitmap) { Init(); Ref(bitmap); }
48
49 // Initialize with raw data
50 wxBitmap(const char bits[], int width, int height, int depth = 1);
51
52 // Initialize with XPM data
53 #ifndef __DIGITALMARS__
54 wxBitmap(const char **data) { CreateFromXpm(data); }
55 #endif
56 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
57
58 // Load a file or resource
59 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
60
61 // New constructor for generalised creation from data
62 wxBitmap(void *data, long type, int width, int height, int depth = 1);
63
64 // Create a new, uninitialized bitmap of the given size and depth (if it
65 // is omitted, will create a bitmap compatible with the display)
66 //
67 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
68 // taking a DC argument if you want to force using DDB in this case
69 wxBitmap(int width, int height, int depth = -1);
70
71 // Create a bitmap compatible with the given DC
72 wxBitmap(int width, int height, const wxDC& dc);
73
74 #if wxUSE_IMAGE
75 // Convert from wxImage
76 wxBitmap(const wxImage& image, int depth = -1)
77 { (void)CreateFromImage(image, depth); }
78
79 // Create a DDB compatible with the given DC from wxImage
80 wxBitmap(const wxImage& image, const wxDC& dc)
81 { (void)CreateFromImage(image, dc); }
82 #endif // wxUSE_IMAGE
83
84 // we must have this, otherwise icons are silently copied into bitmaps using
85 // the copy ctor but the resulting bitmap is invalid!
86 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
87
88 wxBitmap& operator=(const wxBitmap& bitmap)
89 {
90 if ( m_refData != bitmap.m_refData )
91 Ref(bitmap);
92 return *this;
93 }
94
95 wxBitmap& operator=(const wxIcon& icon)
96 {
97 (void)CopyFromIcon(icon);
98
99 return *this;
100 }
101
102 wxBitmap& operator=(const wxCursor& cursor)
103 {
104 (void)CopyFromCursor(cursor);
105
106 return *this;
107 }
108
109 virtual ~wxBitmap();
110
111 #if wxUSE_IMAGE
112 wxImage ConvertToImage() const;
113 #endif // wxUSE_IMAGE
114
115 // get the given part of bitmap
116 wxBitmap GetSubBitmap( const wxRect& rect ) const;
117
118 // copies the contents and mask of the given (colour) icon to the bitmap
119 bool CopyFromIcon(const wxIcon& icon);
120
121 // copies the contents and mask of the given cursor to the bitmap
122 bool CopyFromCursor(const wxCursor& cursor);
123
124 // copies from a device independent bitmap
125 bool CopyFromDIB(const wxDIB& dib);
126
127 virtual bool Create(int width, int height, int depth = -1);
128 virtual bool Create(int width, int height, const wxDC& dc);
129 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
130 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
131 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
132
133 wxBitmapRefData *GetBitmapData() const
134 { return (wxBitmapRefData *)m_refData; }
135
136 // raw bitmap access support functions
137 bool GetRawData(wxRawBitmapData *data);
138 void UngetRawData(wxRawBitmapData *);
139
140 #if wxUSE_PALETTE
141 wxPalette* GetPalette() const;
142 void SetPalette(const wxPalette& palette);
143 #endif // wxUSE_PALETTE
144
145 wxMask *GetMask() const;
146 void SetMask(wxMask *mask);
147
148 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
149 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
150
151 // these functions are internal and shouldn't be used, they risk to
152 // disappear in the future
153 bool HasAlpha() const;
154 void UseAlpha();
155
156 #if WXWIN_COMPATIBILITY_2_4
157 // these functions do nothing and are only there for backwards
158 // compatibility
159 wxDEPRECATED( int GetQuality() const );
160 wxDEPRECATED( void SetQuality(int quality) );
161 #endif // WXWIN_COMPATIBILITY_2_4
162
163 #if WXWIN_COMPATIBILITY_2
164 void SetOk(bool isOk);
165 #endif // WXWIN_COMPATIBILITY_2
166
167 #if WXWIN_COMPATIBILITY
168 #if wxUSE_PALETTE
169 wxPalette *GetColourMap() const { return GetPalette(); }
170 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
171 #endif // wxUSE_PALETTE
172 #endif // WXWIN_COMPATIBILITY
173
174 // implementation only from now on
175 // -------------------------------
176
177 public:
178 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
179 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
180
181 #ifdef __WXDEBUG__
182 void SetSelectedInto(wxDC *dc);
183 wxDC *GetSelectedInto() const;
184 #endif // __WXDEBUG__
185
186 protected:
187 // common part of all ctors
188 void Init();
189
190 virtual wxGDIImageRefData *CreateData() const;
191
192 // creates the bitmap from XPM data, supposed to be called from ctor
193 bool CreateFromXpm(const char **bits);
194
195 // creates an uninitialized bitmap, called from Create()s above
196 bool DoCreate(int w, int h, int depth, WXHDC hdc);
197
198 #if wxUSE_IMAGE
199 // creates the bitmap from wxImage, supposed to be called from ctor
200 bool CreateFromImage(const wxImage& image, int depth);
201
202 // creates a DDB from wxImage, supposed to be called from ctor
203 bool CreateFromImage(const wxImage& image, const wxDC& dc);
204
205 // common part of the 2 methods above (hdc may be 0)
206 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
207 #endif // wxUSE_IMAGE
208
209 private:
210 #ifdef __WIN32__
211 // common part of CopyFromIcon/CopyFromCursor for Win32
212 bool CopyFromIconOrCursor(const wxGDIImage& icon);
213 #endif // __WIN32__
214
215 DECLARE_DYNAMIC_CLASS(wxBitmap)
216 };
217
218 // ----------------------------------------------------------------------------
219 // wxMask: a mono bitmap used for drawing bitmaps transparently.
220 // ----------------------------------------------------------------------------
221
222 class WXDLLEXPORT wxMask : public wxObject
223 {
224 public:
225 wxMask();
226
227 // Construct a mask from a bitmap and a colour indicating the transparent
228 // area
229 wxMask(const wxBitmap& bitmap, const wxColour& colour);
230
231 // Construct a mask from a bitmap and a palette index indicating the
232 // transparent area
233 wxMask(const wxBitmap& bitmap, int paletteIndex);
234
235 // Construct a mask from a mono bitmap (copies the bitmap).
236 wxMask(const wxBitmap& bitmap);
237
238 // construct a mask from the givne bitmap handle
239 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
240
241 virtual ~wxMask();
242
243 bool Create(const wxBitmap& bitmap, const wxColour& colour);
244 bool Create(const wxBitmap& bitmap, int paletteIndex);
245 bool Create(const wxBitmap& bitmap);
246
247 // Implementation
248 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
249 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
250
251 protected:
252 WXHBITMAP m_maskBitmap;
253
254 DECLARE_DYNAMIC_CLASS(wxMask)
255 };
256
257 // ----------------------------------------------------------------------------
258 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
259 // ----------------------------------------------------------------------------
260
261 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
262 {
263 public:
264 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
265 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
266 : wxGDIImageHandler(name, ext, type)
267 {
268 }
269
270 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
271 // old class which worked only with bitmaps
272 virtual bool Create(wxBitmap *bitmap,
273 void *data,
274 long flags,
275 int width, int height, int depth = 1);
276 virtual bool LoadFile(wxBitmap *bitmap,
277 const wxString& name,
278 long flags,
279 int desiredWidth, int desiredHeight);
280 virtual bool SaveFile(wxBitmap *bitmap,
281 const wxString& name,
282 int type,
283 const wxPalette *palette = NULL);
284
285 virtual bool Create(wxGDIImage *image,
286 void *data,
287 long flags,
288 int width, int height, int depth = 1);
289 virtual bool Load(wxGDIImage *image,
290 const wxString& name,
291 long flags,
292 int desiredWidth, int desiredHeight);
293 virtual bool Save(wxGDIImage *image,
294 const wxString& name,
295 int type);
296
297 private:
298 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
299 };
300
301 #endif
302 // _WX_BITMAP_H_