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