]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: bitmap.h | |
3 | // Purpose: wxBitmap class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
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/gdiobj.h" | |
20 | #include "wx/gdicmn.h" | |
21 | #include "wx/palette.h" | |
22 | ||
23 | // Bitmap | |
24 | class WXDLLEXPORT wxDC; | |
25 | class WXDLLEXPORT wxControl; | |
26 | class WXDLLEXPORT wxBitmap; | |
27 | class WXDLLEXPORT wxBitmapHandler; | |
28 | class WXDLLEXPORT wxIcon; | |
29 | class WXDLLEXPORT wxCursor; | |
30 | class WXDLLEXPORT wxImage; | |
31 | ||
32 | // A mask is a mono bitmap used for drawing bitmaps | |
33 | // transparently. | |
34 | class WXDLLEXPORT wxMask: public wxObject | |
35 | { | |
36 | DECLARE_DYNAMIC_CLASS(wxMask) | |
37 | ||
38 | public: | |
39 | wxMask(); | |
40 | ||
41 | // Construct a mask from a bitmap and a colour indicating | |
42 | // the transparent area | |
43 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
44 | ||
45 | // Construct a mask from a bitmap and a palette index indicating | |
46 | // the transparent area | |
47 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
48 | ||
49 | // Construct a mask from a mono bitmap (copies the bitmap). | |
50 | wxMask(const wxBitmap& bitmap); | |
51 | ||
52 | ~wxMask(); | |
53 | ||
54 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
55 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
56 | bool Create(const wxBitmap& bitmap); | |
57 | ||
58 | WXPixmap GetPixmap() const { return m_pixmap; } | |
59 | void SetPixmap(WXPixmap pixmap) { m_pixmap = pixmap; } | |
60 | ||
61 | protected: | |
62 | WXPixmap m_pixmap; | |
63 | }; | |
64 | ||
65 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData | |
66 | { | |
67 | friend class WXDLLEXPORT wxBitmap; | |
68 | friend class WXDLLEXPORT wxIcon; | |
69 | friend class WXDLLEXPORT wxCursor; | |
70 | public: | |
71 | wxBitmapRefData(); | |
72 | ~wxBitmapRefData(); | |
73 | ||
74 | public: | |
75 | int m_width; | |
76 | int m_height; | |
77 | int m_depth; | |
78 | bool m_ok; | |
79 | // XXX int m_numColors; | |
80 | wxPalette m_bitmapPalette; | |
81 | // XXX int m_quality; | |
82 | ||
83 | wxMask * m_bitmapMask; // Optional mask | |
84 | ||
85 | // Motif implementation | |
86 | public: | |
87 | WXPixmap m_pixmap; | |
88 | WXDisplay* m_display; | |
89 | // XXX bool m_freePixmap; | |
90 | #if 0 | |
91 | unsigned long* m_freeColors; | |
92 | long m_freeColorsCount; | |
93 | #endif | |
94 | ||
95 | #if 0 | |
96 | // These 5 variables are for wxControl | |
97 | WXPixmap m_insensPixmap ; | |
98 | WXPixmap m_labelPixmap ; | |
99 | WXPixmap m_armPixmap ; | |
100 | #endif | |
101 | #if 0 | |
102 | WXImage* m_image ; | |
103 | WXImage* m_insensImage ; | |
104 | #endif | |
105 | }; | |
106 | ||
107 | #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) | |
108 | ||
109 | class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase | |
110 | { | |
111 | public: | |
112 | wxBitmapHandler() : wxBitmapHandlerBase() { } | |
113 | ||
114 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, | |
115 | int width, int height, int depth = 1) | |
116 | { | |
117 | return false; | |
118 | } | |
119 | ||
120 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
121 | int desiredWidth, int desiredHeight) | |
122 | { | |
123 | return false; | |
124 | } | |
125 | ||
126 | virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, | |
127 | int type, const wxPalette *palette = NULL) | |
128 | { | |
129 | return false; | |
130 | } | |
131 | private: | |
132 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
133 | }; | |
134 | ||
135 | #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) | |
136 | ||
137 | class WXDLLEXPORT wxBitmap: public wxBitmapBase | |
138 | { | |
139 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
140 | ||
141 | friend class WXDLLEXPORT wxBitmapHandler; | |
142 | ||
143 | public: | |
144 | wxBitmap(); // Platform-specific | |
145 | ||
146 | // Copy constructors | |
147 | wxBitmap(const wxBitmap& bitmap) | |
148 | { Ref(bitmap); } | |
149 | ||
150 | // Initialize with raw XBM data | |
151 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
152 | ||
153 | // from XPM | |
154 | wxBitmap(const char **data) { (void)CreateFromXpm(data); } | |
155 | wxBitmap(char **data) { (void)CreateFromXpm((const char **)data); } | |
156 | ||
157 | #if 0 | |
158 | // Initialize with XPM data -- deprecated | |
159 | wxBitmap(char **data, wxControl* control); | |
160 | #endif | |
161 | ||
162 | // Load a file or resource | |
163 | wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_XPM); | |
164 | ||
165 | // Constructor for generalised creation from data | |
166 | wxBitmap(void *data, wxBitmapType type, | |
167 | int width, int height, int depth = 1); | |
168 | ||
169 | // If depth is omitted, will create a bitmap compatible with the display | |
170 | wxBitmap(int width, int height, int depth = -1); | |
171 | ||
172 | // Convert from wxImage: | |
173 | wxBitmap(const wxImage& image, int depth = -1) { (void)CreateFromImage(image, depth); } | |
174 | ||
175 | ~wxBitmap(); | |
176 | ||
177 | virtual bool Create(int width, int height, int depth = -1); | |
178 | virtual bool Create(void *data, wxBitmapType type, | |
179 | int width, int height, int depth = 1); | |
180 | ||
181 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
182 | ||
183 | virtual bool LoadFile(const wxString& name, | |
184 | wxBitmapType type = wxBITMAP_TYPE_XPM); | |
185 | virtual bool SaveFile(const wxString& name, wxBitmapType type, | |
186 | const wxPalette *cmap = NULL) const; | |
187 | ||
188 | wxImage ConvertToImage() const; | |
189 | ||
190 | // copies the contents and mask of the given (colour) icon to the bitmap | |
191 | virtual bool CopyFromIcon(const wxIcon& icon); | |
192 | ||
193 | bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); } | |
194 | int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } | |
195 | int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } | |
196 | int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } | |
197 | // XXX int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } | |
198 | void SetWidth(int w); | |
199 | void SetHeight(int h); | |
200 | void SetDepth(int d); | |
201 | // XXX void SetQuality(int q); | |
202 | void SetOk(bool isOk); | |
203 | ||
204 | wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } | |
205 | void SetPalette(const wxPalette& palette); | |
206 | ||
207 | wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); } | |
208 | void SetMask(wxMask *mask) ; | |
209 | ||
210 | wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } | |
211 | bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } | |
212 | bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } | |
213 | ||
214 | // Format handling | |
215 | static void InitStandardHandlers(); | |
216 | ||
217 | // Motif implementation | |
218 | public: | |
219 | WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; } | |
220 | WXPixmap GetPixmap() const { return (WXPixmap) M_BITMAPDATA->m_pixmap; } | |
221 | #if 0 | |
222 | virtual WXPixmap GetLabelPixmap(WXWidget w) ; | |
223 | virtual WXPixmap GetArmPixmap(WXWidget w) ; | |
224 | virtual WXPixmap GetInsensPixmap(WXWidget w = (WXWidget) 0) ; | |
225 | #endif | |
226 | void SetPixmapNull() { M_BITMAPDATA->m_pixmap = 0; } | |
227 | ||
228 | protected: | |
229 | bool CreateFromXpm(const char **bits); | |
230 | bool CreateFromImage(const wxImage& image, int depth); | |
231 | }; | |
232 | ||
233 | // Creates a bitmap with transparent areas drawn in | |
234 | // the given colour. | |
235 | wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour); | |
236 | ||
237 | #endif | |
238 | // _WX_BITMAP_H_ |