]>
Commit | Line | Data |
---|---|---|
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 |
23 | class WXDLLEXPORT wxDC; |
24 | class WXDLLEXPORT wxControl; | |
25 | class WXDLLEXPORT wxBitmap; | |
26 | class WXDLLEXPORT wxBitmapHandler; | |
8bbbae21 | 27 | class WXDLLEXPORT wxBitmapRefData; |
2bda0e17 | 28 | class WXDLLEXPORT wxIcon; |
6d167489 | 29 | class WXDLLEXPORT wxMask; |
2bda0e17 | 30 | class WXDLLEXPORT wxCursor; |
03ab016d | 31 | class WXDLLEXPORT wxControl; |
fd859211 | 32 | class WXDLLEXPORT wxImage; |
d275c7eb | 33 | class WXDLLEXPORT wxPalette; |
2bda0e17 | 34 | |
6d167489 VZ |
35 | // ---------------------------------------------------------------------------- |
36 | // wxBitmap: a mono or colour bitmap | |
37 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 38 | |
6d167489 VZ |
39 | class WXDLLEXPORT wxBitmap : public wxGDIImage |
40 | { | |
2bda0e17 | 41 | public: |
4fe5383d VZ |
42 | // default ctor creates an invalid bitmap, you must Create() it later |
43 | wxBitmap() { Init(); } | |
44 | ||
45 | // Copy constructors | |
46 | wxBitmap(const wxBitmap& bitmap) { Init(); Ref(bitmap); } | |
47 | ||
48 | // Initialize with raw data | |
49 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
50 | ||
51 | // Initialize with XPM data | |
4b7f2165 VZ |
52 | wxBitmap(const char **data) { CreateFromXpm(data); } |
53 | wxBitmap(char **data) { CreateFromXpm((const char **)data); } | |
2bda0e17 | 54 | |
4fe5383d | 55 | // Load a file or resource |
2aeec9ec | 56 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); |
2bda0e17 | 57 | |
4fe5383d VZ |
58 | // New constructor for generalised creation from data |
59 | wxBitmap(void *data, long type, int width, int height, int depth = 1); | |
2bda0e17 | 60 | |
4fe5383d VZ |
61 | // If depth is omitted, will create a bitmap compatible with the display |
62 | wxBitmap(int width, int height, int depth = -1); | |
6d51f220 VZ |
63 | |
64 | #if wxUSE_IMAGE | |
fd859211 | 65 | // Convert from wxImage: |
6d51f220 VZ |
66 | wxBitmap(const wxImage& image, int depth = -1) |
67 | { (void)CreateFromImage(image, depth); } | |
68 | #endif // wxUSE_IMAGE | |
2bda0e17 | 69 | |
4fe5383d VZ |
70 | // we must have this, otherwise icons are silently copied into bitmaps using |
71 | // the copy ctor but the resulting bitmap is invalid! | |
72 | wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); } | |
2bda0e17 | 73 | |
4fe5383d VZ |
74 | wxBitmap& operator=(const wxBitmap& bitmap) |
75 | { | |
76 | if ( m_refData != bitmap.m_refData ) | |
77 | Ref(bitmap); | |
78 | return *this; | |
79 | } | |
2bda0e17 | 80 | |
4fe5383d VZ |
81 | wxBitmap& operator=(const wxIcon& icon) |
82 | { | |
83 | (void)CopyFromIcon(icon); | |
07cf98cb | 84 | |
4fe5383d VZ |
85 | return *this; |
86 | } | |
07cf98cb | 87 | |
6d167489 VZ |
88 | wxBitmap& operator=(const wxCursor& cursor) |
89 | { | |
90 | (void)CopyFromCursor(cursor); | |
91 | ||
92 | return *this; | |
93 | } | |
94 | ||
4fe5383d | 95 | virtual ~wxBitmap(); |
2bda0e17 | 96 | |
6d51f220 | 97 | #if wxUSE_IMAGE |
fd859211 | 98 | wxImage ConvertToImage() const; |
6d51f220 | 99 | #endif // wxUSE_IMAGE |
fd859211 | 100 | |
4b7f2165 | 101 | // get the given part of bitmap |
8208e181 | 102 | wxBitmap GetSubBitmap( const wxRect& rect ) const; |
6d51f220 | 103 | |
4fe5383d VZ |
104 | // copies the contents and mask of the given (colour) icon to the bitmap |
105 | bool CopyFromIcon(const wxIcon& icon); | |
2bda0e17 | 106 | |
6d167489 VZ |
107 | // copies the contents and mask of the given cursor to the bitmap |
108 | bool CopyFromCursor(const wxCursor& cursor); | |
109 | ||
4fe5383d VZ |
110 | virtual bool Create(int width, int height, int depth = -1); |
111 | virtual bool Create(void *data, long type, int width, int height, int depth = 1); | |
112 | virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); | |
113 | virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); | |
114 | ||
8bbbae21 VZ |
115 | wxBitmapRefData *GetBitmapData() const |
116 | { return (wxBitmapRefData *)m_refData; } | |
6d167489 | 117 | |
d275c7eb | 118 | #if wxUSE_PALETTE |
8bbbae21 | 119 | wxPalette* GetPalette() const; |
4fe5383d | 120 | void SetPalette(const wxPalette& palette); |
d275c7eb | 121 | #endif // wxUSE_PALETTE |
2bda0e17 | 122 | |
8bbbae21 | 123 | wxMask *GetMask() const; |
acf8e3d2 | 124 | void SetMask(wxMask *mask); |
2bda0e17 | 125 | |
f6bcfd97 BP |
126 | bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } |
127 | bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } | |
ce3ed50d | 128 | |
acf8e3d2 VZ |
129 | // this function is internal and shouldn't be used, it risks to disappear |
130 | bool HasAlpha() const; | |
8bbbae21 VZ |
131 | |
132 | #if WXWIN_COMPATIBILITY_2_4 | |
133 | // these functions do nothing and are only there for backwards | |
134 | // compatibility | |
135 | wxDEPRECATED( int GetQuality() const ); | |
136 | wxDEPRECATED( void SetQuality(int quality) ); | |
137 | #endif // WXWIN_COMPATIBILITY_2_4 | |
138 | ||
6d167489 VZ |
139 | #if WXWIN_COMPATIBILITY_2 |
140 | void SetOk(bool isOk); | |
141 | #endif // WXWIN_COMPATIBILITY_2 | |
2bda0e17 | 142 | |
d275c7eb | 143 | #if wxUSE_PALETTE |
6d167489 VZ |
144 | #if WXWIN_COMPATIBILITY |
145 | wxPalette *GetColourMap() const { return GetPalette(); } | |
146 | void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); }; | |
147 | #endif // WXWIN_COMPATIBILITY | |
d275c7eb | 148 | #endif // wxUSE_PALETTE |
2bda0e17 | 149 | |
4fe5383d | 150 | // Implementation |
2bda0e17 | 151 | public: |
6d167489 VZ |
152 | void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); } |
153 | WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); } | |
154 | ||
acf8e3d2 | 155 | #ifdef __WXDEBUG__ |
8bbbae21 VZ |
156 | void SetSelectedInto(wxDC *dc); |
157 | wxDC *GetSelectedInto() const; | |
acf8e3d2 | 158 | #endif // __WXDEBUG__ |
6d167489 VZ |
159 | |
160 | // Creates a bitmap that matches the device context's depth, from an | |
161 | // arbitray bitmap. At present, the original bitmap must have an associated | |
162 | // palette. (TODO: use a default palette if no palette exists.) This | |
163 | // function is necessary for you to Blit an arbitrary bitmap (which may | |
164 | // have the wrong depth). wxDC::SelectObject will compare the depth of the | |
165 | // bitmap with the DC's depth, and create a new bitmap if the depths | |
166 | // differ. Eventually we should perhaps make this a public API function so | |
167 | // that an app can efficiently produce bitmaps of the correct depth. The | |
168 | // Windows solution is to use SetDibBits to blit an arbotrary DIB directly | |
169 | // to a DC, but this is too Windows-specific, hence this solution of | |
170 | // quietly converting the wxBitmap. Contributed by Frederic Villeneuve | |
171 | // <frederic.villeneuve@natinst.com> | |
4fe5383d VZ |
172 | wxBitmap GetBitmapForDC(wxDC& dc) const; |
173 | ||
174 | protected: | |
175 | // common part of all ctors | |
176 | void Init(); | |
7b46ecac | 177 | |
8bbbae21 | 178 | virtual wxGDIImageRefData *CreateData() const; |
6d167489 | 179 | |
4b7f2165 VZ |
180 | // creates the bitmap from XPM data, supposed to be called from ctor |
181 | bool CreateFromXpm(const char **bits); | |
6d51f220 VZ |
182 | |
183 | #if wxUSE_IMAGE | |
fd859211 VS |
184 | // creates the bitmap from wxImage, supposed to be called from ctor |
185 | bool CreateFromImage(const wxImage& image, int depth); | |
6d51f220 | 186 | #endif // wxUSE_IMAGE |
4b7f2165 | 187 | |
0becd470 VZ |
188 | #if wxUSE_DIB_FOR_BITMAP |
189 | void *CreateDIB(int width, int height, int depth); | |
8bbbae21 | 190 | |
0becd470 | 191 | void CopyDIBLine(void* src, void* dest, int count) const; |
8bbbae21 | 192 | #endif // wxUSE_DIB_FOR_BITMAP |
0becd470 | 193 | |
4fe5383d | 194 | private: |
6d167489 VZ |
195 | #ifdef __WIN32__ |
196 | // common part of CopyFromIcon/CopyFromCursor for Win32 | |
197 | bool CopyFromIconOrCursor(const wxGDIImage& icon); | |
198 | #endif // __WIN32__ | |
199 | ||
4fe5383d | 200 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
2bda0e17 | 201 | }; |
ce3ed50d | 202 | |
6d167489 VZ |
203 | // ---------------------------------------------------------------------------- |
204 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
205 | // ---------------------------------------------------------------------------- | |
206 | ||
207 | class WXDLLEXPORT wxMask : public wxObject | |
208 | { | |
209 | public: | |
210 | wxMask(); | |
211 | ||
212 | // Construct a mask from a bitmap and a colour indicating the transparent | |
213 | // area | |
214 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
215 | ||
216 | // Construct a mask from a bitmap and a palette index indicating the | |
217 | // transparent area | |
218 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
219 | ||
220 | // Construct a mask from a mono bitmap (copies the bitmap). | |
221 | wxMask(const wxBitmap& bitmap); | |
222 | ||
223 | // construct a mask from the givne bitmap handle | |
224 | wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; } | |
225 | ||
226 | virtual ~wxMask(); | |
227 | ||
228 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
229 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
230 | bool Create(const wxBitmap& bitmap); | |
231 | ||
232 | // Implementation | |
233 | WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } | |
234 | void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } | |
235 | ||
236 | protected: | |
237 | WXHBITMAP m_maskBitmap; | |
238 | ||
239 | DECLARE_DYNAMIC_CLASS(wxMask) | |
240 | }; | |
241 | ||
242 | // ---------------------------------------------------------------------------- | |
243 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
244 | // ---------------------------------------------------------------------------- | |
245 | ||
246 | class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler | |
247 | { | |
248 | public: | |
249 | wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; } | |
250 | wxBitmapHandler(const wxString& name, const wxString& ext, long type) | |
251 | : wxGDIImageHandler(name, ext, type) | |
252 | { | |
253 | } | |
254 | ||
255 | // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the | |
256 | // old class which worked only with bitmaps | |
257 | virtual bool Create(wxBitmap *bitmap, | |
258 | void *data, | |
259 | long flags, | |
260 | int width, int height, int depth = 1); | |
261 | virtual bool LoadFile(wxBitmap *bitmap, | |
262 | const wxString& name, | |
263 | long flags, | |
264 | int desiredWidth, int desiredHeight); | |
265 | virtual bool SaveFile(wxBitmap *bitmap, | |
266 | const wxString& name, | |
267 | int type, | |
268 | const wxPalette *palette = NULL); | |
269 | ||
270 | virtual bool Create(wxGDIImage *image, | |
271 | void *data, | |
272 | long flags, | |
273 | int width, int height, int depth = 1); | |
274 | virtual bool Load(wxGDIImage *image, | |
275 | const wxString& name, | |
276 | long flags, | |
277 | int desiredWidth, int desiredHeight); | |
278 | virtual bool Save(wxGDIImage *image, | |
279 | const wxString& name, | |
280 | int type); | |
281 | ||
282 | private: | |
283 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
284 | }; | |
285 | ||
2bda0e17 | 286 | #endif |
bbcdf8bc | 287 | // _WX_BITMAP_H_ |