]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/bitmap.h
Renamed HasChildren() to IsContainer(), added GetParent() to wxDataViewModel
[wxWidgets.git] / include / wx / msw / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BITMAP_H_
13 #define _WX_BITMAP_H_
14
15 #include "wx/msw/gdiimage.h"
16 #include "wx/palette.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxBitmap;
19 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
20 class WXDLLIMPEXP_FWD_CORE wxBitmapRefData;
21 class WXDLLIMPEXP_FWD_CORE wxControl;
22 class WXDLLIMPEXP_FWD_CORE wxCursor;
23 class WXDLLIMPEXP_FWD_CORE wxDC;
24 #if wxUSE_WXDIB
25 class WXDLLIMPEXP_FWD_CORE wxDIB;
26 #endif
27 class WXDLLIMPEXP_FWD_CORE wxIcon;
28 class WXDLLIMPEXP_FWD_CORE wxImage;
29 class WXDLLIMPEXP_FWD_CORE wxMask;
30 class WXDLLIMPEXP_FWD_CORE wxPalette;
31 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
32
33 // ----------------------------------------------------------------------------
34 // wxBitmap: a mono or colour bitmap
35 // ----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxBitmap : public wxGDIImage
38 {
39 public:
40 // default ctor creates an invalid bitmap, you must Create() it later
41 wxBitmap() { }
42
43 // Initialize with raw data
44 wxBitmap(const char bits[], int width, int height, int depth = 1);
45
46 // Initialize with XPM data
47 wxBitmap(const char* const* data);
48 #ifdef wxNEEDS_CHARPP
49 wxBitmap(char** data)
50 {
51 *this = wxBitmap(wx_const_cast(const char* const*, data));
52 }
53 #endif
54
55 // Load a file or resource
56 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
57
58 // New constructor for generalised creation from data
59 wxBitmap(const void* data, long type, int width, int height, int depth = 1);
60
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
66 wxBitmap(int width, int height, int depth = -1);
67
68 // Create a bitmap compatible with the given DC
69 wxBitmap(int width, int height, const wxDC& dc);
70
71 #if wxUSE_IMAGE
72 // Convert from wxImage
73 wxBitmap(const wxImage& image, int depth = -1)
74 { (void)CreateFromImage(image, depth); }
75
76 // Create a DDB compatible with the given DC from wxImage
77 wxBitmap(const wxImage& image, const wxDC& dc)
78 { (void)CreateFromImage(image, dc); }
79 #endif // wxUSE_IMAGE
80
81 // we must have this, otherwise icons are silently copied into bitmaps using
82 // the copy ctor but the resulting bitmap is invalid!
83 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
84
85 wxBitmap& operator=(const wxIcon& icon)
86 {
87 (void)CopyFromIcon(icon);
88
89 return *this;
90 }
91
92 wxBitmap& operator=(const wxCursor& cursor)
93 {
94 (void)CopyFromCursor(cursor);
95
96 return *this;
97 }
98
99 virtual ~wxBitmap();
100
101 #if wxUSE_IMAGE
102 wxImage ConvertToImage() const;
103 #endif // wxUSE_IMAGE
104
105 // get the given part of bitmap
106 wxBitmap GetSubBitmap( const wxRect& rect ) const;
107
108 // copies the contents and mask of the given (colour) icon to the bitmap
109 bool CopyFromIcon(const wxIcon& icon);
110
111 // copies the contents and mask of the given cursor to the bitmap
112 bool CopyFromCursor(const wxCursor& cursor);
113
114 #if wxUSE_WXDIB
115 // copies from a device independent bitmap
116 bool CopyFromDIB(const wxDIB& dib);
117 #endif
118
119 virtual bool Create(int width, int height, int depth = -1);
120 virtual bool Create(int width, int height, const wxDC& dc);
121 virtual bool Create(const void* data, long type, int width, int height, int depth = 1);
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
125 wxBitmapRefData *GetBitmapData() const
126 { return (wxBitmapRefData *)m_refData; }
127
128 // raw bitmap access support functions
129 void *GetRawData(wxPixelDataBase& data, int bpp);
130 void UngetRawData(wxPixelDataBase& data);
131
132 #if wxUSE_PALETTE
133 wxPalette* GetPalette() const;
134 void SetPalette(const wxPalette& palette);
135 #endif // wxUSE_PALETTE
136
137 wxMask *GetMask() const;
138 wxBitmap GetMaskBitmap() const;
139 void SetMask(wxMask *mask);
140
141 // these functions are internal and shouldn't be used, they risk to
142 // disappear in the future
143 bool HasAlpha() const;
144 void UseAlpha();
145
146 // implementation only from now on
147 // -------------------------------
148
149 public:
150 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
151 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
152
153 #ifdef __WXDEBUG__
154 void SetSelectedInto(wxDC *dc);
155 wxDC *GetSelectedInto() const;
156 #endif // __WXDEBUG__
157
158 protected:
159 virtual wxGDIImageRefData *CreateData() const;
160 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
161
162 // creates an uninitialized bitmap, called from Create()s above
163 bool DoCreate(int w, int h, int depth, WXHDC hdc);
164
165 #if wxUSE_IMAGE
166 // creates the bitmap from wxImage, supposed to be called from ctor
167 bool CreateFromImage(const wxImage& image, int depth);
168
169 // creates a DDB from wxImage, supposed to be called from ctor
170 bool CreateFromImage(const wxImage& image, const wxDC& dc);
171
172 // common part of the 2 methods above (hdc may be 0)
173 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc);
174 #endif // wxUSE_IMAGE
175
176 private:
177 // common part of CopyFromIcon/CopyFromCursor for Win32
178 bool CopyFromIconOrCursor(const wxGDIImage& icon);
179
180
181 DECLARE_DYNAMIC_CLASS(wxBitmap)
182 };
183
184 // ----------------------------------------------------------------------------
185 // wxMask: a mono bitmap used for drawing bitmaps transparently.
186 // ----------------------------------------------------------------------------
187
188 class WXDLLEXPORT wxMask : public wxObject
189 {
190 public:
191 wxMask();
192
193 // Copy constructor
194 wxMask(const wxMask &mask);
195
196 // Construct a mask from a bitmap and a colour indicating the transparent
197 // area
198 wxMask(const wxBitmap& bitmap, const wxColour& colour);
199
200 // Construct a mask from a bitmap and a palette index indicating the
201 // transparent area
202 wxMask(const wxBitmap& bitmap, int paletteIndex);
203
204 // Construct a mask from a mono bitmap (copies the bitmap).
205 wxMask(const wxBitmap& bitmap);
206
207 // construct a mask from the givne bitmap handle
208 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
209
210 virtual ~wxMask();
211
212 bool Create(const wxBitmap& bitmap, const wxColour& colour);
213 bool Create(const wxBitmap& bitmap, int paletteIndex);
214 bool Create(const wxBitmap& bitmap);
215
216 // Implementation
217 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
218 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
219
220 protected:
221 WXHBITMAP m_maskBitmap;
222
223 DECLARE_DYNAMIC_CLASS(wxMask)
224 };
225
226 // ----------------------------------------------------------------------------
227 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
228 // ----------------------------------------------------------------------------
229
230 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
231 {
232 public:
233 wxBitmapHandler() { }
234 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
235 : wxGDIImageHandler(name, ext, type)
236 {
237 }
238
239 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
240 // old class which worked only with bitmaps
241 virtual bool Create(wxBitmap *bitmap,
242 const void* data,
243 long flags,
244 int width, int height, int depth = 1);
245 virtual bool LoadFile(wxBitmap *bitmap,
246 const wxString& name,
247 long flags,
248 int desiredWidth, int desiredHeight);
249 virtual bool SaveFile(wxBitmap *bitmap,
250 const wxString& name,
251 int type,
252 const wxPalette *palette = NULL);
253
254 virtual bool Create(wxGDIImage *image,
255 const void* data,
256 long flags,
257 int width, int height, int depth = 1);
258 virtual bool Load(wxGDIImage *image,
259 const wxString& name,
260 long flags,
261 int desiredWidth, int desiredHeight);
262 virtual bool Save(wxGDIImage *image,
263 const wxString& name,
264 int type);
265
266 private:
267 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
268 };
269
270 #endif
271 // _WX_BITMAP_H_