]>
Commit | Line | Data |
---|---|---|
ffecfa5a JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/palmos/bitmap.h | |
3 | // Purpose: wxBitmap class | |
e1d63b79 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
ffecfa5a JS |
5 | // Modified by: |
6 | // Created: 10/13/04 | |
e1d63b79 | 7 | // RCS-ID: $Id$ |
ffecfa5a JS |
8 | // Copyright: (c) William Osborne |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
ffecfa5a JS |
15 | #include "wx/palmos/gdiimage.h" |
16 | #include "wx/gdicmn.h" | |
17 | #include "wx/palette.h" | |
18 | ||
19 | class WXDLLEXPORT wxBitmap; | |
20 | class WXDLLEXPORT wxBitmapHandler; | |
21 | class WXDLLEXPORT wxBitmapRefData; | |
22 | class WXDLLEXPORT wxControl; | |
23 | class WXDLLEXPORT wxCursor; | |
24 | class WXDLLEXPORT wxDC; | |
25 | #if wxUSE_WXDIB | |
26 | class WXDLLEXPORT wxDIB; | |
27 | #endif | |
28 | class WXDLLEXPORT wxIcon; | |
29 | class WXDLLEXPORT wxImage; | |
30 | class WXDLLEXPORT wxMask; | |
31 | class WXDLLEXPORT wxPalette; | |
32 | class WXDLLEXPORT wxPixelDataBase; | |
33 | ||
34 | // ---------------------------------------------------------------------------- | |
35 | // wxBitmap: a mono or colour bitmap | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | class WXDLLEXPORT wxBitmap : public wxGDIImage | |
39 | { | |
40 | public: | |
41 | // default ctor creates an invalid bitmap, you must Create() it later | |
42 | wxBitmap() { Init(); } | |
43 | ||
ffecfa5a JS |
44 | // Initialize with raw data |
45 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
46 | ||
47 | // Initialize with XPM data | |
452418c4 | 48 | wxBitmap(const char* const* data); |
ffecfa5a JS |
49 | |
50 | // Load a file or resource | |
51 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); | |
52 | ||
53 | // New constructor for generalised creation from data | |
452418c4 | 54 | wxBitmap(const void* data, long type, int width, int height, int depth = 1); |
ffecfa5a JS |
55 | |
56 | // Create a new, uninitialized bitmap of the given size and depth (if it | |
57 | // is omitted, will create a bitmap compatible with the display) | |
58 | // | |
59 | // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor | |
60 | // taking a DC argument if you want to force using DDB in this case | |
61 | wxBitmap(int width, int height, int depth = -1); | |
62 | ||
63 | // Create a bitmap compatible with the given DC | |
64 | wxBitmap(int width, int height, const wxDC& dc); | |
65 | ||
66 | #if wxUSE_IMAGE && wxUSE_WXDIB | |
67 | // Convert from wxImage | |
68 | wxBitmap(const wxImage& image, int depth = -1) | |
69 | { (void)CreateFromImage(image, depth); } | |
70 | ||
71 | // Create a DDB compatible with the given DC from wxImage | |
72 | wxBitmap(const wxImage& image, const wxDC& dc) | |
73 | { (void)CreateFromImage(image, dc); } | |
74 | #endif // wxUSE_IMAGE | |
75 | ||
76 | // we must have this, otherwise icons are silently copied into bitmaps using | |
77 | // the copy ctor but the resulting bitmap is invalid! | |
78 | wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); } | |
79 | ||
ffecfa5a JS |
80 | wxBitmap& operator=(const wxIcon& icon) |
81 | { | |
82 | (void)CopyFromIcon(icon); | |
83 | ||
84 | return *this; | |
85 | } | |
86 | ||
87 | wxBitmap& operator=(const wxCursor& cursor) | |
88 | { | |
89 | (void)CopyFromCursor(cursor); | |
90 | ||
91 | return *this; | |
92 | } | |
93 | ||
94 | virtual ~wxBitmap(); | |
95 | ||
96 | #if wxUSE_IMAGE && wxUSE_WXDIB | |
97 | wxImage ConvertToImage() const; | |
98 | #endif // wxUSE_IMAGE | |
99 | ||
100 | // get the given part of bitmap | |
101 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
102 | ||
103 | // copies the contents and mask of the given (colour) icon to the bitmap | |
104 | bool CopyFromIcon(const wxIcon& icon); | |
105 | ||
106 | // copies the contents and mask of the given cursor to the bitmap | |
107 | bool CopyFromCursor(const wxCursor& cursor); | |
108 | ||
109 | #if wxUSE_WXDIB | |
110 | // copies from a device independent bitmap | |
111 | bool CopyFromDIB(const wxDIB& dib); | |
112 | #endif | |
113 | ||
114 | virtual bool Create(int width, int height, int depth = -1); | |
115 | virtual bool Create(int width, int height, const wxDC& dc); | |
452418c4 | 116 | virtual bool Create(const void* data, long type, int width, int height, int depth = 1); |
ffecfa5a JS |
117 | virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); |
118 | virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); | |
119 | ||
120 | wxBitmapRefData *GetBitmapData() const | |
121 | { return (wxBitmapRefData *)m_refData; } | |
122 | ||
123 | // raw bitmap access support functions | |
124 | void *GetRawData(wxPixelDataBase& data, int bpp); | |
125 | void UngetRawData(wxPixelDataBase& data); | |
126 | ||
127 | #if wxUSE_PALETTE | |
128 | wxPalette* GetPalette() const; | |
129 | void SetPalette(const wxPalette& palette); | |
130 | #endif // wxUSE_PALETTE | |
131 | ||
132 | wxMask *GetMask() const; | |
133 | void SetMask(wxMask *mask); | |
134 | ||
ffecfa5a JS |
135 | // these functions are internal and shouldn't be used, they risk to |
136 | // disappear in the future | |
137 | bool HasAlpha() const; | |
138 | void UseAlpha(); | |
139 | ||
ffecfa5a JS |
140 | // implementation only from now on |
141 | // ------------------------------- | |
142 | ||
143 | public: | |
144 | void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); } | |
145 | WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); } | |
146 | ||
147 | #ifdef __WXDEBUG__ | |
148 | void SetSelectedInto(wxDC *dc); | |
149 | wxDC *GetSelectedInto() const; | |
150 | #endif // __WXDEBUG__ | |
151 | ||
152 | protected: | |
153 | // common part of all ctors | |
154 | void Init(); | |
155 | ||
156 | virtual wxGDIImageRefData *CreateData() const; | |
157 | ||
ffecfa5a JS |
158 | // creates an uninitialized bitmap, called from Create()s above |
159 | bool DoCreate(int w, int h, int depth, WXHDC hdc); | |
160 | ||
161 | #if wxUSE_IMAGE && wxUSE_WXDIB | |
162 | // creates the bitmap from wxImage, supposed to be called from ctor | |
163 | bool CreateFromImage(const wxImage& image, int depth); | |
164 | ||
165 | // creates a DDB from wxImage, supposed to be called from ctor | |
166 | bool CreateFromImage(const wxImage& image, const wxDC& dc); | |
167 | ||
168 | // common part of the 2 methods above (hdc may be 0) | |
169 | bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc); | |
170 | #endif // wxUSE_IMAGE | |
171 | ||
172 | private: | |
ffecfa5a JS |
173 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
174 | }; | |
175 | ||
176 | // ---------------------------------------------------------------------------- | |
177 | // wxMask: a mono bitmap used for drawing bitmaps transparently. | |
178 | // ---------------------------------------------------------------------------- | |
179 | ||
180 | class WXDLLEXPORT wxMask : public wxObject | |
181 | { | |
182 | public: | |
183 | wxMask(); | |
184 | ||
185 | // Construct a mask from a bitmap and a colour indicating the transparent | |
186 | // area | |
187 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
188 | ||
189 | // Construct a mask from a bitmap and a palette index indicating the | |
190 | // transparent area | |
191 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
192 | ||
193 | // Construct a mask from a mono bitmap (copies the bitmap). | |
194 | wxMask(const wxBitmap& bitmap); | |
195 | ||
196 | // construct a mask from the givne bitmap handle | |
197 | wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; } | |
198 | ||
199 | virtual ~wxMask(); | |
200 | ||
201 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
202 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
203 | bool Create(const wxBitmap& bitmap); | |
204 | ||
205 | // Implementation | |
206 | WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } | |
207 | void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } | |
208 | ||
209 | protected: | |
210 | WXHBITMAP m_maskBitmap; | |
211 | ||
212 | DECLARE_DYNAMIC_CLASS(wxMask) | |
213 | }; | |
214 | ||
215 | // ---------------------------------------------------------------------------- | |
216 | // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file | |
217 | // ---------------------------------------------------------------------------- | |
218 | ||
219 | class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler | |
220 | { | |
221 | public: | |
222 | wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; } | |
223 | wxBitmapHandler(const wxString& name, const wxString& ext, long type) | |
224 | : wxGDIImageHandler(name, ext, type) | |
225 | { | |
226 | } | |
227 | ||
228 | // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the | |
229 | // old class which worked only with bitmaps | |
230 | virtual bool Create(wxBitmap *bitmap, | |
452418c4 | 231 | const void* data, |
ffecfa5a JS |
232 | long flags, |
233 | int width, int height, int depth = 1); | |
234 | virtual bool LoadFile(wxBitmap *bitmap, | |
235 | const wxString& name, | |
236 | long flags, | |
237 | int desiredWidth, int desiredHeight); | |
238 | virtual bool SaveFile(wxBitmap *bitmap, | |
239 | const wxString& name, | |
240 | int type, | |
241 | const wxPalette *palette = NULL); | |
242 | ||
243 | virtual bool Create(wxGDIImage *image, | |
452418c4 | 244 | const void* data, |
ffecfa5a JS |
245 | long flags, |
246 | int width, int height, int depth = 1); | |
247 | virtual bool Load(wxGDIImage *image, | |
248 | const wxString& name, | |
249 | long flags, | |
250 | int desiredWidth, int desiredHeight); | |
251 | virtual bool Save(wxGDIImage *image, | |
252 | const wxString& name, | |
253 | int type); | |
254 | ||
255 | private: | |
256 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
257 | }; | |
258 | ||
259 | #endif | |
260 | // _WX_BITMAP_H_ |