compilation fixes after applying DECLARE_NO_COPY_CLASS() patch
[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 #ifdef __GNUG__
16 #pragma interface "bitmap.h"
17 #endif
18
19 #include "wx/msw/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
22
23 class WXDLLEXPORT wxDC;
24 class WXDLLEXPORT wxControl;
25 class WXDLLEXPORT wxBitmap;
26 class WXDLLEXPORT wxBitmapHandler;
27 class WXDLLEXPORT wxIcon;
28 class WXDLLEXPORT wxMask;
29 class WXDLLEXPORT wxCursor;
30 class WXDLLEXPORT wxControl;
31 class WXDLLEXPORT wxImage;
32 class WXDLLEXPORT wxPalette;
33
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 // ----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
42 {
43 public:
44 wxBitmapRefData();
45 virtual ~wxBitmapRefData() { Free(); }
46
47 virtual void Free();
48
49 public:
50 int m_numColors;
51 #if wxUSE_PALETTE
52 wxPalette m_bitmapPalette;
53 #endif // wxUSE_PALETTE
54 int m_quality;
55
56 // MSW-specific
57 // ------------
58
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;
66
67 #if wxUSE_DIB_FOR_BITMAP
68 WXHANDLE m_hFileMap; // file mapping handle for large DIB's
69 #endif
70
71
72 DECLARE_NO_COPY_CLASS(wxBitmapRefData)
73 };
74
75 // ----------------------------------------------------------------------------
76 // wxBitmap: a mono or colour bitmap
77 // ----------------------------------------------------------------------------
78
79 class WXDLLEXPORT wxBitmap : public wxGDIImage
80 {
81 public:
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
92 wxBitmap(const char **data) { CreateFromXpm(data); }
93 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
94
95 // Load a file or resource
96 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
97
98 // New constructor for generalised creation from data
99 wxBitmap(void *data, long type, int width, int height, int depth = 1);
100
101 // If depth is omitted, will create a bitmap compatible with the display
102 wxBitmap(int width, int height, int depth = -1);
103
104 #if wxUSE_IMAGE
105 // Convert from wxImage:
106 wxBitmap(const wxImage& image, int depth = -1)
107 { (void)CreateFromImage(image, depth); }
108 #endif // wxUSE_IMAGE
109
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); }
113
114 wxBitmap& operator=(const wxBitmap& bitmap)
115 {
116 if ( m_refData != bitmap.m_refData )
117 Ref(bitmap);
118 return *this;
119 }
120
121 wxBitmap& operator=(const wxIcon& icon)
122 {
123 (void)CopyFromIcon(icon);
124
125 return *this;
126 }
127
128 wxBitmap& operator=(const wxCursor& cursor)
129 {
130 (void)CopyFromCursor(cursor);
131
132 return *this;
133 }
134
135 virtual ~wxBitmap();
136
137 #if wxUSE_IMAGE
138 wxImage ConvertToImage() const;
139 #endif // wxUSE_IMAGE
140
141 // get the given part of bitmap
142 wxBitmap GetSubBitmap( const wxRect& rect ) const;
143
144 // copies the contents and mask of the given (colour) icon to the bitmap
145 bool CopyFromIcon(const wxIcon& icon);
146
147 // copies the contents and mask of the given cursor to the bitmap
148 bool CopyFromCursor(const wxCursor& cursor);
149
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
155 wxBitmapRefData *GetBitmapData() const { return (wxBitmapRefData *)m_refData; }
156
157 int GetQuality() const { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); }
158 void SetQuality(int q);
159
160 #if wxUSE_PALETTE
161 wxPalette* GetPalette() const { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); }
162 void SetPalette(const wxPalette& palette);
163 #endif // wxUSE_PALETTE
164
165 wxMask *GetMask() const { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); }
166 void SetMask(wxMask *mask) ;
167
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; }
170
171 #if WXWIN_COMPATIBILITY_2
172 void SetOk(bool isOk);
173 #endif // WXWIN_COMPATIBILITY_2
174
175 #if wxUSE_PALETTE
176 #if WXWIN_COMPATIBILITY
177 wxPalette *GetColourMap() const { return GetPalette(); }
178 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
179 #endif // WXWIN_COMPATIBILITY
180 #endif // wxUSE_PALETTE
181
182 // Implementation
183 public:
184 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
185 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
186
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
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>
207 wxBitmap GetBitmapForDC(wxDC& dc) const;
208
209 protected:
210 // common part of all ctors
211 void Init();
212
213 virtual wxGDIImageRefData *CreateData() const
214 { return new wxBitmapRefData; }
215
216 // creates the bitmap from XPM data, supposed to be called from ctor
217 bool CreateFromXpm(const char **bits);
218
219 #if wxUSE_IMAGE
220 // creates the bitmap from wxImage, supposed to be called from ctor
221 bool CreateFromImage(const wxImage& image, int depth);
222 #endif // wxUSE_IMAGE
223
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
229 private:
230 #ifdef __WIN32__
231 // common part of CopyFromIcon/CopyFromCursor for Win32
232 bool CopyFromIconOrCursor(const wxGDIImage& icon);
233 #endif // __WIN32__
234
235 DECLARE_DYNAMIC_CLASS(wxBitmap)
236 };
237
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
321 #endif
322 // _WX_BITMAP_H_