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