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