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