]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
implemented GetBestSize() (TODO: make this available in generic version as well)
[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
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
2bda0e17 14
6d167489 15#include "wx/msw/gdiimage.h"
2bda0e17
KB
16#include "wx/gdicmn.h"
17#include "wx/palette.h"
18
2bda0e17
KB
19class WXDLLEXPORT wxBitmap;
20class WXDLLEXPORT wxBitmapHandler;
8bbbae21 21class WXDLLEXPORT wxBitmapRefData;
03ab016d 22class WXDLLEXPORT wxControl;
b0ea5d96
VZ
23class WXDLLEXPORT wxCursor;
24class WXDLLEXPORT wxDC;
086b3a5b 25#if wxUSE_WXDIB
b0ea5d96 26class WXDLLEXPORT wxDIB;
086b3a5b 27#endif
b0ea5d96 28class WXDLLEXPORT wxIcon;
fd859211 29class WXDLLEXPORT wxImage;
b0ea5d96 30class WXDLLEXPORT wxMask;
d275c7eb 31class WXDLLEXPORT wxPalette;
b9bcaf11 32class WXDLLEXPORT wxPixelDataBase;
2bda0e17 33
6d167489
VZ
34// ----------------------------------------------------------------------------
35// wxBitmap: a mono or colour bitmap
36// ----------------------------------------------------------------------------
2bda0e17 37
6d167489
VZ
38class WXDLLEXPORT wxBitmap : public wxGDIImage
39{
2bda0e17 40public:
4fe5383d 41 // default ctor creates an invalid bitmap, you must Create() it later
6463b9f5 42 wxBitmap() { Init(); }
4fe5383d
VZ
43
44 // Copy constructors
4dddb8a2 45 wxBitmap(const wxBitmap& bitmap) : wxGDIImage(bitmap) { Init(); Ref(bitmap); }
4fe5383d
VZ
46
47 // Initialize with raw data
48 wxBitmap(const char bits[], int width, int height, int depth = 1);
49
50 // Initialize with XPM data
6463b9f5
JS
51 wxBitmap(const char **data) { CreateFromXpm(data); }
52 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
2bda0e17 53
4fe5383d 54 // Load a file or resource
2aeec9ec 55 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17 56
4fe5383d
VZ
57 // New constructor for generalised creation from data
58 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17 59
2cf45d69
VZ
60 // Create a new, uninitialized bitmap of the given size and depth (if it
61 // is omitted, will create a bitmap compatible with the display)
62 //
63 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
64 // taking a DC argument if you want to force using DDB in this case
4fe5383d 65 wxBitmap(int width, int height, int depth = -1);
6d51f220 66
2cf45d69
VZ
67 // Create a bitmap compatible with the given DC
68 wxBitmap(int width, int height, const wxDC& dc);
69
be69f971 70#if wxUSE_IMAGE && wxUSE_WXDIB
2cf45d69 71 // Convert from wxImage
6463b9f5
JS
72 wxBitmap(const wxImage& image, int depth = -1)
73 { (void)CreateFromImage(image, depth); }
2cf45d69
VZ
74
75 // Create a DDB compatible with the given DC from wxImage
6463b9f5
JS
76 wxBitmap(const wxImage& image, const wxDC& dc)
77 { (void)CreateFromImage(image, dc); }
6d51f220 78#endif // wxUSE_IMAGE
2bda0e17 79
4fe5383d
VZ
80 // we must have this, otherwise icons are silently copied into bitmaps using
81 // the copy ctor but the resulting bitmap is invalid!
6463b9f5 82 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
2bda0e17 83
4fe5383d
VZ
84 wxBitmap& operator=(const wxBitmap& bitmap)
85 {
86 if ( m_refData != bitmap.m_refData )
87 Ref(bitmap);
88 return *this;
89 }
2bda0e17 90
4fe5383d
VZ
91 wxBitmap& operator=(const wxIcon& icon)
92 {
93 (void)CopyFromIcon(icon);
07cf98cb 94
4fe5383d
VZ
95 return *this;
96 }
07cf98cb 97
6d167489
VZ
98 wxBitmap& operator=(const wxCursor& cursor)
99 {
100 (void)CopyFromCursor(cursor);
101
102 return *this;
103 }
104
4fe5383d 105 virtual ~wxBitmap();
2bda0e17 106
be69f971 107#if wxUSE_IMAGE && wxUSE_WXDIB
fd859211 108 wxImage ConvertToImage() const;
6d51f220 109#endif // wxUSE_IMAGE
fd859211 110
4b7f2165 111 // get the given part of bitmap
8208e181 112 wxBitmap GetSubBitmap( const wxRect& rect ) const;
6d51f220 113
4fe5383d
VZ
114 // copies the contents and mask of the given (colour) icon to the bitmap
115 bool CopyFromIcon(const wxIcon& icon);
2bda0e17 116
6d167489
VZ
117 // copies the contents and mask of the given cursor to the bitmap
118 bool CopyFromCursor(const wxCursor& cursor);
119
086b3a5b 120#if wxUSE_WXDIB
b0ea5d96
VZ
121 // copies from a device independent bitmap
122 bool CopyFromDIB(const wxDIB& dib);
086b3a5b 123#endif
b0ea5d96 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;
ec023a6e 144 wxBitmap GetMaskBitmap() const;
acf8e3d2 145 void SetMask(wxMask *mask);
2bda0e17 146
f6bcfd97
BP
147 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
148 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
ce3ed50d 149
10b41b53
VZ
150 // these functions are internal and shouldn't be used, they risk to
151 // disappear in the future
acf8e3d2 152 bool HasAlpha() const;
10b41b53 153 void UseAlpha();
8bbbae21
VZ
154
155#if WXWIN_COMPATIBILITY_2_4
156 // these functions do nothing and are only there for backwards
157 // compatibility
158 wxDEPRECATED( int GetQuality() const );
159 wxDEPRECATED( void SetQuality(int quality) );
160#endif // WXWIN_COMPATIBILITY_2_4
161
2cf45d69
VZ
162 // implementation only from now on
163 // -------------------------------
2bda0e17 164
2bda0e17 165public:
6d167489
VZ
166 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
167 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
168
acf8e3d2 169#ifdef __WXDEBUG__
8bbbae21
VZ
170 void SetSelectedInto(wxDC *dc);
171 wxDC *GetSelectedInto() const;
acf8e3d2 172#endif // __WXDEBUG__
6d167489 173
4fe5383d
VZ
174protected:
175 // common part of all ctors
176 void Init();
7b46ecac 177
8bbbae21 178 virtual wxGDIImageRefData *CreateData() const;
7ff64980 179 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
6d167489 180
4b7f2165
VZ
181 // creates the bitmap from XPM data, supposed to be called from ctor
182 bool CreateFromXpm(const char **bits);
6d51f220 183
2cf45d69
VZ
184 // creates an uninitialized bitmap, called from Create()s above
185 bool DoCreate(int w, int h, int depth, WXHDC hdc);
186
be69f971 187#if wxUSE_IMAGE && wxUSE_WXDIB
fd859211
VS
188 // creates the bitmap from wxImage, supposed to be called from ctor
189 bool CreateFromImage(const wxImage& image, int depth);
4b7f2165 190
2cf45d69
VZ
191 // creates a DDB from wxImage, supposed to be called from ctor
192 bool CreateFromImage(const wxImage& image, const wxDC& dc);
8bbbae21 193
2cf45d69
VZ
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
0becd470 197
4fe5383d 198private:
6d167489
VZ
199#ifdef __WIN32__
200 // common part of CopyFromIcon/CopyFromCursor for Win32
201 bool CopyFromIconOrCursor(const wxGDIImage& icon);
202#endif // __WIN32__
203
4fe5383d 204 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 205};
ce3ed50d 206
6d167489
VZ
207// ----------------------------------------------------------------------------
208// wxMask: a mono bitmap used for drawing bitmaps transparently.
209// ----------------------------------------------------------------------------
210
211class WXDLLEXPORT wxMask : public wxObject
212{
213public:
214 wxMask();
215
216 // Construct a mask from a bitmap and a colour indicating the transparent
217 // area
218 wxMask(const wxBitmap& bitmap, const wxColour& colour);
219
220 // Construct a mask from a bitmap and a palette index indicating the
221 // transparent area
222 wxMask(const wxBitmap& bitmap, int paletteIndex);
223
224 // Construct a mask from a mono bitmap (copies the bitmap).
225 wxMask(const wxBitmap& bitmap);
226
227 // construct a mask from the givne bitmap handle
228 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
229
230 virtual ~wxMask();
231
232 bool Create(const wxBitmap& bitmap, const wxColour& colour);
233 bool Create(const wxBitmap& bitmap, int paletteIndex);
234 bool Create(const wxBitmap& bitmap);
235
236 // Implementation
237 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
238 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
239
240protected:
241 WXHBITMAP m_maskBitmap;
242
243 DECLARE_DYNAMIC_CLASS(wxMask)
244};
245
246// ----------------------------------------------------------------------------
247// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
248// ----------------------------------------------------------------------------
249
250class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
251{
252public:
253 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
254 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
255 : wxGDIImageHandler(name, ext, type)
256 {
257 }
258
259 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
260 // old class which worked only with bitmaps
261 virtual bool Create(wxBitmap *bitmap,
262 void *data,
263 long flags,
264 int width, int height, int depth = 1);
265 virtual bool LoadFile(wxBitmap *bitmap,
266 const wxString& name,
267 long flags,
268 int desiredWidth, int desiredHeight);
269 virtual bool SaveFile(wxBitmap *bitmap,
270 const wxString& name,
271 int type,
272 const wxPalette *palette = NULL);
273
274 virtual bool Create(wxGDIImage *image,
275 void *data,
276 long flags,
277 int width, int height, int depth = 1);
278 virtual bool Load(wxGDIImage *image,
279 const wxString& name,
280 long flags,
281 int desiredWidth, int desiredHeight);
282 virtual bool Save(wxGDIImage *image,
283 const wxString& name,
284 int type);
285
286private:
287 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
288};
289
2bda0e17 290#endif
bbcdf8bc 291 // _WX_BITMAP_H_