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