]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
removed curico files
[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 wxDC;
24class WXDLLEXPORT wxControl;
25class WXDLLEXPORT wxBitmap;
26class WXDLLEXPORT wxBitmapHandler;
8bbbae21 27class WXDLLEXPORT wxBitmapRefData;
2bda0e17 28class WXDLLEXPORT wxIcon;
6d167489 29class WXDLLEXPORT wxMask;
2bda0e17 30class WXDLLEXPORT wxCursor;
03ab016d 31class WXDLLEXPORT wxControl;
fd859211 32class WXDLLEXPORT wxImage;
d275c7eb 33class WXDLLEXPORT wxPalette;
2cf45d69 34class WXDLLEXPORT wxRawBitmapData;
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
4fe5383d 122 virtual bool Create(int width, int height, int depth = -1);
2cf45d69 123 virtual bool Create(int width, int height, const wxDC& dc);
4fe5383d
VZ
124 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
125 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
126 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
127
8bbbae21
VZ
128 wxBitmapRefData *GetBitmapData() const
129 { return (wxBitmapRefData *)m_refData; }
6d167489 130
2cf45d69
VZ
131 // raw bitmap access support functions
132 bool GetRawData(wxRawBitmapData *data);
133 void UngetRawData(wxRawBitmapData *) { /* nothing to do here */ }
134
d275c7eb 135#if wxUSE_PALETTE
8bbbae21 136 wxPalette* GetPalette() const;
4fe5383d 137 void SetPalette(const wxPalette& palette);
d275c7eb 138#endif // wxUSE_PALETTE
2bda0e17 139
8bbbae21 140 wxMask *GetMask() const;
acf8e3d2 141 void SetMask(wxMask *mask);
2bda0e17 142
f6bcfd97
BP
143 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
144 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
ce3ed50d 145
acf8e3d2
VZ
146 // this function is internal and shouldn't be used, it risks to disappear
147 bool HasAlpha() const;
8bbbae21
VZ
148
149#if WXWIN_COMPATIBILITY_2_4
150 // these functions do nothing and are only there for backwards
151 // compatibility
152 wxDEPRECATED( int GetQuality() const );
153 wxDEPRECATED( void SetQuality(int quality) );
154#endif // WXWIN_COMPATIBILITY_2_4
155
6d167489
VZ
156#if WXWIN_COMPATIBILITY_2
157 void SetOk(bool isOk);
158#endif // WXWIN_COMPATIBILITY_2
2bda0e17 159
6d167489 160#if WXWIN_COMPATIBILITY
2cf45d69 161#if wxUSE_PALETTE
6d167489
VZ
162 wxPalette *GetColourMap() const { return GetPalette(); }
163 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
d275c7eb 164#endif // wxUSE_PALETTE
2cf45d69
VZ
165#endif // WXWIN_COMPATIBILITY
166
167 // implementation only from now on
168 // -------------------------------
2bda0e17 169
2bda0e17 170public:
6d167489
VZ
171 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
172 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
173
acf8e3d2 174#ifdef __WXDEBUG__
8bbbae21
VZ
175 void SetSelectedInto(wxDC *dc);
176 wxDC *GetSelectedInto() const;
acf8e3d2 177#endif // __WXDEBUG__
6d167489
VZ
178
179 // Creates a bitmap that matches the device context's depth, from an
180 // arbitray bitmap. At present, the original bitmap must have an associated
181 // palette. (TODO: use a default palette if no palette exists.) This
182 // function is necessary for you to Blit an arbitrary bitmap (which may
183 // have the wrong depth). wxDC::SelectObject will compare the depth of the
184 // bitmap with the DC's depth, and create a new bitmap if the depths
185 // differ. Eventually we should perhaps make this a public API function so
186 // that an app can efficiently produce bitmaps of the correct depth. The
187 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
188 // to a DC, but this is too Windows-specific, hence this solution of
189 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
190 // <frederic.villeneuve@natinst.com>
4fe5383d
VZ
191 wxBitmap GetBitmapForDC(wxDC& dc) const;
192
193protected:
194 // common part of all ctors
195 void Init();
7b46ecac 196
8bbbae21 197 virtual wxGDIImageRefData *CreateData() const;
6d167489 198
4b7f2165
VZ
199 // creates the bitmap from XPM data, supposed to be called from ctor
200 bool CreateFromXpm(const char **bits);
6d51f220 201
2cf45d69
VZ
202 // creates an uninitialized bitmap, called from Create()s above
203 bool DoCreate(int w, int h, int depth, WXHDC hdc);
204
6d51f220 205#if wxUSE_IMAGE
fd859211
VS
206 // creates the bitmap from wxImage, supposed to be called from ctor
207 bool CreateFromImage(const wxImage& image, int depth);
4b7f2165 208
2cf45d69
VZ
209 // creates a DDB from wxImage, supposed to be called from ctor
210 bool CreateFromImage(const wxImage& image, const wxDC& dc);
8bbbae21 211
2cf45d69
VZ
212 // common part of the 2 methods above (hdc may be 0)
213 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
214#endif // wxUSE_IMAGE
0becd470 215
4fe5383d 216private:
6d167489
VZ
217#ifdef __WIN32__
218 // common part of CopyFromIcon/CopyFromCursor for Win32
219 bool CopyFromIconOrCursor(const wxGDIImage& icon);
220#endif // __WIN32__
221
4fe5383d 222 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 223};
ce3ed50d 224
6d167489
VZ
225// ----------------------------------------------------------------------------
226// wxMask: a mono bitmap used for drawing bitmaps transparently.
227// ----------------------------------------------------------------------------
228
229class WXDLLEXPORT wxMask : public wxObject
230{
231public:
232 wxMask();
233
234 // Construct a mask from a bitmap and a colour indicating the transparent
235 // area
236 wxMask(const wxBitmap& bitmap, const wxColour& colour);
237
238 // Construct a mask from a bitmap and a palette index indicating the
239 // transparent area
240 wxMask(const wxBitmap& bitmap, int paletteIndex);
241
242 // Construct a mask from a mono bitmap (copies the bitmap).
243 wxMask(const wxBitmap& bitmap);
244
245 // construct a mask from the givne bitmap handle
246 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
247
248 virtual ~wxMask();
249
250 bool Create(const wxBitmap& bitmap, const wxColour& colour);
251 bool Create(const wxBitmap& bitmap, int paletteIndex);
252 bool Create(const wxBitmap& bitmap);
253
254 // Implementation
255 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
256 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
257
258protected:
259 WXHBITMAP m_maskBitmap;
260
261 DECLARE_DYNAMIC_CLASS(wxMask)
262};
263
264// ----------------------------------------------------------------------------
265// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
266// ----------------------------------------------------------------------------
267
268class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
269{
270public:
271 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
272 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
273 : wxGDIImageHandler(name, ext, type)
274 {
275 }
276
277 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
278 // old class which worked only with bitmaps
279 virtual bool Create(wxBitmap *bitmap,
280 void *data,
281 long flags,
282 int width, int height, int depth = 1);
283 virtual bool LoadFile(wxBitmap *bitmap,
284 const wxString& name,
285 long flags,
286 int desiredWidth, int desiredHeight);
287 virtual bool SaveFile(wxBitmap *bitmap,
288 const wxString& name,
289 int type,
290 const wxPalette *palette = NULL);
291
292 virtual bool Create(wxGDIImage *image,
293 void *data,
294 long flags,
295 int width, int height, int depth = 1);
296 virtual bool Load(wxGDIImage *image,
297 const wxString& name,
298 long flags,
299 int desiredWidth, int desiredHeight);
300 virtual bool Save(wxGDIImage *image,
301 const wxString& name,
302 int type);
303
304private:
305 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
306};
307
2bda0e17 308#endif
bbcdf8bc 309 // _WX_BITMAP_H_