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