]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
MinGW compilation fixes.
[wxWidgets.git] / include / wx / msw / bitmap.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
6d167489 2// Name: wx/msw/bitmap.h
2bda0e17
KB
3// Purpose: wxBitmap class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
bbcdf8bc 8// Copyright: (c) Julian Smart
4fe5383d 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
2bda0e17
KB
14
15#ifdef __GNUG__
4fe5383d 16 #pragma interface "bitmap.h"
2bda0e17
KB
17#endif
18
6d167489 19#include "wx/msw/gdiimage.h"
2bda0e17
KB
20#include "wx/gdicmn.h"
21#include "wx/palette.h"
22
2bda0e17
KB
23class WXDLLEXPORT wxBitmap;
24class WXDLLEXPORT wxBitmapHandler;
8bbbae21 25class WXDLLEXPORT wxBitmapRefData;
03ab016d 26class WXDLLEXPORT wxControl;
b0ea5d96
VZ
27class WXDLLEXPORT wxCursor;
28class WXDLLEXPORT wxDC;
29class WXDLLEXPORT wxDIB;
30class WXDLLEXPORT wxIcon;
fd859211 31class WXDLLEXPORT wxImage;
b0ea5d96 32class WXDLLEXPORT wxMask;
d275c7eb 33class WXDLLEXPORT wxPalette;
b9bcaf11 34class WXDLLEXPORT wxPixelDataBase;
2bda0e17 35
6d167489
VZ
36// ----------------------------------------------------------------------------
37// wxBitmap: a mono or colour bitmap
38// ----------------------------------------------------------------------------
2bda0e17 39
6d167489
VZ
40class WXDLLEXPORT wxBitmap : public wxGDIImage
41{
2bda0e17 42public:
4fe5383d
VZ
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
4b7f2165
VZ
53 wxBitmap(const char **data) { CreateFromXpm(data); }
54 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
2bda0e17 55
4fe5383d 56 // Load a file or resource
2aeec9ec 57 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17 58
4fe5383d
VZ
59 // New constructor for generalised creation from data
60 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17 61
2cf45d69
VZ
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)
64 //
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
4fe5383d 67 wxBitmap(int width, int height, int depth = -1);
6d51f220 68
2cf45d69
VZ
69 // Create a bitmap compatible with the given DC
70 wxBitmap(int width, int height, const wxDC& dc);
71
6d51f220 72#if wxUSE_IMAGE
2cf45d69 73 // Convert from wxImage
6d51f220
VZ
74 wxBitmap(const wxImage& image, int depth = -1)
75 { (void)CreateFromImage(image, depth); }
2cf45d69
VZ
76
77 // Create a DDB compatible with the given DC from wxImage
78 wxBitmap(const wxImage& image, const wxDC& dc)
79 { (void)CreateFromImage(image, dc); }
6d51f220 80#endif // wxUSE_IMAGE
2bda0e17 81
4fe5383d
VZ
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) { Init(); CopyFromIcon(icon); }
2bda0e17 85
4fe5383d
VZ
86 wxBitmap& operator=(const wxBitmap& bitmap)
87 {
88 if ( m_refData != bitmap.m_refData )
89 Ref(bitmap);
90 return *this;
91 }
2bda0e17 92
4fe5383d
VZ
93 wxBitmap& operator=(const wxIcon& icon)
94 {
95 (void)CopyFromIcon(icon);
07cf98cb 96
4fe5383d
VZ
97 return *this;
98 }
07cf98cb 99
6d167489
VZ
100 wxBitmap& operator=(const wxCursor& cursor)
101 {
102 (void)CopyFromCursor(cursor);
103
104 return *this;
105 }
106
4fe5383d 107 virtual ~wxBitmap();
2bda0e17 108
6d51f220 109#if wxUSE_IMAGE
fd859211 110 wxImage ConvertToImage() const;
6d51f220 111#endif // wxUSE_IMAGE
fd859211 112
4b7f2165 113 // get the given part of bitmap
8208e181 114 wxBitmap GetSubBitmap( const wxRect& rect ) const;
6d51f220 115
4fe5383d
VZ
116 // copies the contents and mask of the given (colour) icon to the bitmap
117 bool CopyFromIcon(const wxIcon& icon);
2bda0e17 118
6d167489
VZ
119 // copies the contents and mask of the given cursor to the bitmap
120 bool CopyFromCursor(const wxCursor& cursor);
121
b0ea5d96
VZ
122 // copies from a device independent bitmap
123 bool CopyFromDIB(const wxDIB& dib);
124
4fe5383d 125 virtual bool Create(int width, int height, int depth = -1);
2cf45d69 126 virtual bool Create(int width, int height, const wxDC& dc);
4fe5383d
VZ
127 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
128 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
129 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
130
8bbbae21
VZ
131 wxBitmapRefData *GetBitmapData() const
132 { return (wxBitmapRefData *)m_refData; }
6d167489 133
2cf45d69 134 // raw bitmap access support functions
b9bcaf11
VZ
135 void *GetRawData(wxPixelDataBase& data, int bpp);
136 void UngetRawData(wxPixelDataBase& data);
2cf45d69 137
d275c7eb 138#if wxUSE_PALETTE
8bbbae21 139 wxPalette* GetPalette() const;
4fe5383d 140 void SetPalette(const wxPalette& palette);
d275c7eb 141#endif // wxUSE_PALETTE
2bda0e17 142
8bbbae21 143 wxMask *GetMask() const;
acf8e3d2 144 void SetMask(wxMask *mask);
2bda0e17 145
f6bcfd97
BP
146 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
147 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
ce3ed50d 148
10b41b53
VZ
149 // these functions are internal and shouldn't be used, they risk to
150 // disappear in the future
acf8e3d2 151 bool HasAlpha() const;
10b41b53 152 void UseAlpha();
8bbbae21
VZ
153
154#if WXWIN_COMPATIBILITY_2_4
155 // these functions do nothing and are only there for backwards
156 // compatibility
157 wxDEPRECATED( int GetQuality() const );
158 wxDEPRECATED( void SetQuality(int quality) );
159#endif // WXWIN_COMPATIBILITY_2_4
160
6d167489
VZ
161#if WXWIN_COMPATIBILITY_2
162 void SetOk(bool isOk);
163#endif // WXWIN_COMPATIBILITY_2
2bda0e17 164
6d167489 165#if WXWIN_COMPATIBILITY
2cf45d69 166#if wxUSE_PALETTE
6d167489
VZ
167 wxPalette *GetColourMap() const { return GetPalette(); }
168 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
d275c7eb 169#endif // wxUSE_PALETTE
2cf45d69
VZ
170#endif // WXWIN_COMPATIBILITY
171
172 // implementation only from now on
173 // -------------------------------
2bda0e17 174
2bda0e17 175public:
6d167489
VZ
176 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
177 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
178
acf8e3d2 179#ifdef __WXDEBUG__
8bbbae21
VZ
180 void SetSelectedInto(wxDC *dc);
181 wxDC *GetSelectedInto() const;
acf8e3d2 182#endif // __WXDEBUG__
6d167489 183
4fe5383d
VZ
184protected:
185 // common part of all ctors
186 void Init();
7b46ecac 187
8bbbae21 188 virtual wxGDIImageRefData *CreateData() const;
6d167489 189
4b7f2165
VZ
190 // creates the bitmap from XPM data, supposed to be called from ctor
191 bool CreateFromXpm(const char **bits);
6d51f220 192
2cf45d69
VZ
193 // creates an uninitialized bitmap, called from Create()s above
194 bool DoCreate(int w, int h, int depth, WXHDC hdc);
195
6d51f220 196#if wxUSE_IMAGE
fd859211
VS
197 // creates the bitmap from wxImage, supposed to be called from ctor
198 bool CreateFromImage(const wxImage& image, int depth);
4b7f2165 199
2cf45d69
VZ
200 // creates a DDB from wxImage, supposed to be called from ctor
201 bool CreateFromImage(const wxImage& image, const wxDC& dc);
8bbbae21 202
2cf45d69
VZ
203 // common part of the 2 methods above (hdc may be 0)
204 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
205#endif // wxUSE_IMAGE
0becd470 206
4fe5383d 207private:
6d167489
VZ
208#ifdef __WIN32__
209 // common part of CopyFromIcon/CopyFromCursor for Win32
210 bool CopyFromIconOrCursor(const wxGDIImage& icon);
211#endif // __WIN32__
212
4fe5383d 213 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 214};
ce3ed50d 215
6d167489
VZ
216// ----------------------------------------------------------------------------
217// wxMask: a mono bitmap used for drawing bitmaps transparently.
218// ----------------------------------------------------------------------------
219
220class WXDLLEXPORT wxMask : public wxObject
221{
222public:
223 wxMask();
224
225 // Construct a mask from a bitmap and a colour indicating the transparent
226 // area
227 wxMask(const wxBitmap& bitmap, const wxColour& colour);
228
229 // Construct a mask from a bitmap and a palette index indicating the
230 // transparent area
231 wxMask(const wxBitmap& bitmap, int paletteIndex);
232
233 // Construct a mask from a mono bitmap (copies the bitmap).
234 wxMask(const wxBitmap& bitmap);
235
236 // construct a mask from the givne bitmap handle
237 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
238
239 virtual ~wxMask();
240
241 bool Create(const wxBitmap& bitmap, const wxColour& colour);
242 bool Create(const wxBitmap& bitmap, int paletteIndex);
243 bool Create(const wxBitmap& bitmap);
244
245 // Implementation
246 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
247 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
248
249protected:
250 WXHBITMAP m_maskBitmap;
251
252 DECLARE_DYNAMIC_CLASS(wxMask)
253};
254
255// ----------------------------------------------------------------------------
256// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
257// ----------------------------------------------------------------------------
258
259class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
260{
261public:
262 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
263 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
264 : wxGDIImageHandler(name, ext, type)
265 {
266 }
267
268 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
269 // old class which worked only with bitmaps
270 virtual bool Create(wxBitmap *bitmap,
271 void *data,
272 long flags,
273 int width, int height, int depth = 1);
274 virtual bool LoadFile(wxBitmap *bitmap,
275 const wxString& name,
276 long flags,
277 int desiredWidth, int desiredHeight);
278 virtual bool SaveFile(wxBitmap *bitmap,
279 const wxString& name,
280 int type,
281 const wxPalette *palette = NULL);
282
283 virtual bool Create(wxGDIImage *image,
284 void *data,
285 long flags,
286 int width, int height, int depth = 1);
287 virtual bool Load(wxGDIImage *image,
288 const wxString& name,
289 long flags,
290 int desiredWidth, int desiredHeight);
291 virtual bool Save(wxGDIImage *image,
292 const wxString& name,
293 int type);
294
295private:
296 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
297};
298
2bda0e17 299#endif
bbcdf8bc 300 // _WX_BITMAP_H_