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