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