]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/msw/bitmap.h
Removed erroneous copyright names and corrected licence spelling
[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#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
23class WXDLLEXPORT wxDC;
24class WXDLLEXPORT wxControl;
25class WXDLLEXPORT wxBitmap;
26class WXDLLEXPORT wxBitmapHandler;
27class WXDLLEXPORT wxBitmapRefData;
28class WXDLLEXPORT wxIcon;
29class WXDLLEXPORT wxMask;
30class WXDLLEXPORT wxCursor;
31class WXDLLEXPORT wxControl;
32class WXDLLEXPORT wxImage;
33class WXDLLEXPORT wxPalette;
34
35// ----------------------------------------------------------------------------
36// wxBitmap: a mono or colour bitmap
37// ----------------------------------------------------------------------------
38
39class WXDLLEXPORT wxBitmap : public wxGDIImage
40{
41public:
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
52 wxBitmap(const char **data) { CreateFromXpm(data); }
53 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
54
55 // Load a file or resource
56 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
57
58 // New constructor for generalised creation from data
59 wxBitmap(void *data, long type, int width, int height, int depth = 1);
60
61 // If depth is omitted, will create a bitmap compatible with the display
62 wxBitmap(int width, int height, int depth = -1);
63
64#if wxUSE_IMAGE
65 // Convert from wxImage:
66 wxBitmap(const wxImage& image, int depth = -1)
67 { (void)CreateFromImage(image, depth); }
68#endif // wxUSE_IMAGE
69
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); }
73
74 wxBitmap& operator=(const wxBitmap& bitmap)
75 {
76 if ( m_refData != bitmap.m_refData )
77 Ref(bitmap);
78 return *this;
79 }
80
81 wxBitmap& operator=(const wxIcon& icon)
82 {
83 (void)CopyFromIcon(icon);
84
85 return *this;
86 }
87
88 wxBitmap& operator=(const wxCursor& cursor)
89 {
90 (void)CopyFromCursor(cursor);
91
92 return *this;
93 }
94
95 virtual ~wxBitmap();
96
97#if wxUSE_IMAGE
98 wxImage ConvertToImage() const;
99#endif // wxUSE_IMAGE
100
101 // get the given part of bitmap
102 wxBitmap GetSubBitmap( const wxRect& rect ) const;
103
104 // copies the contents and mask of the given (colour) icon to the bitmap
105 bool CopyFromIcon(const wxIcon& icon);
106
107 // copies the contents and mask of the given cursor to the bitmap
108 bool CopyFromCursor(const wxCursor& cursor);
109
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
115 wxBitmapRefData *GetBitmapData() const
116 { return (wxBitmapRefData *)m_refData; }
117
118#if wxUSE_PALETTE
119 wxPalette* GetPalette() const;
120 void SetPalette(const wxPalette& palette);
121#endif // wxUSE_PALETTE
122
123 wxMask *GetMask() const;
124 void SetMask(wxMask *mask);
125
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; }
128
129 // this function is internal and shouldn't be used, it risks to disappear
130 bool HasAlpha() const;
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
139#if WXWIN_COMPATIBILITY_2
140 void SetOk(bool isOk);
141#endif // WXWIN_COMPATIBILITY_2
142
143#if wxUSE_PALETTE
144#if WXWIN_COMPATIBILITY
145 wxPalette *GetColourMap() const { return GetPalette(); }
146 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
147#endif // WXWIN_COMPATIBILITY
148#endif // wxUSE_PALETTE
149
150 // Implementation
151public:
152 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
153 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
154
155#ifdef __WXDEBUG__
156 void SetSelectedInto(wxDC *dc);
157 wxDC *GetSelectedInto() const;
158#endif // __WXDEBUG__
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>
172 wxBitmap GetBitmapForDC(wxDC& dc) const;
173
174protected:
175 // common part of all ctors
176 void Init();
177
178 virtual wxGDIImageRefData *CreateData() const;
179
180 // creates the bitmap from XPM data, supposed to be called from ctor
181 bool CreateFromXpm(const char **bits);
182
183#if wxUSE_IMAGE
184 // creates the bitmap from wxImage, supposed to be called from ctor
185 bool CreateFromImage(const wxImage& image, int depth);
186#endif // wxUSE_IMAGE
187
188#if wxUSE_DIB_FOR_BITMAP
189 void *CreateDIB(int width, int height, int depth);
190
191 void CopyDIBLine(void* src, void* dest, int count) const;
192#endif // wxUSE_DIB_FOR_BITMAP
193
194private:
195#ifdef __WIN32__
196 // common part of CopyFromIcon/CopyFromCursor for Win32
197 bool CopyFromIconOrCursor(const wxGDIImage& icon);
198#endif // __WIN32__
199
200 DECLARE_DYNAMIC_CLASS(wxBitmap)
201};
202
203// ----------------------------------------------------------------------------
204// wxMask: a mono bitmap used for drawing bitmaps transparently.
205// ----------------------------------------------------------------------------
206
207class WXDLLEXPORT wxMask : public wxObject
208{
209public:
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
236protected:
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
246class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
247{
248public:
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
282private:
283 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
284};
285
286#endif
287 // _WX_BITMAP_H_