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