]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/bitmap.h | |
3 | // Purpose: wxBitmap class interface | |
4 | // Author: Vaclav Slavik | |
5 | // Modified by: | |
6 | // Created: 22.04.01 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_BITMAP_H_BASE_ |
13 | #define _WX_BITMAP_H_BASE_ | |
c801d85f | 14 | |
1e6feb95 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
1e6feb95 VZ |
19 | #include "wx/defs.h" |
20 | #include "wx/object.h" | |
21 | #include "wx/string.h" | |
1e6feb95 | 22 | #include "wx/gdiobj.h" |
22bd9387 | 23 | #include "wx/gdicmn.h" // for wxBitmapType |
acb53ea5 | 24 | #include "wx/colour.h" |
1e6feb95 | 25 | |
1e6feb95 VZ |
26 | class WXDLLEXPORT wxBitmap; |
27 | class WXDLLEXPORT wxBitmapHandler; | |
87f83ac8 | 28 | class WXDLLEXPORT wxIcon; |
22bd9387 VZ |
29 | class WXDLLEXPORT wxImage; |
30 | class WXDLLEXPORT wxMask; | |
31 | class WXDLLEXPORT wxPalette; | |
1e6feb95 | 32 | |
6f5d7825 RR |
33 | // ---------------------------------------------------------------------------- |
34 | // wxVariant support | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | #if wxUSE_VARIANT | |
38 | #include "wx/variant.h" | |
39 | DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLEXPORT) | |
40 | #endif | |
41 | ||
87f83ac8 VZ |
42 | // ---------------------------------------------------------------------------- |
43 | // wxMask represents the transparent area of the bitmap | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | class WXDLLEXPORT wxMaskBase : public wxObject | |
47 | { | |
48 | public: | |
49 | // create the mask from bitmap pixels of the given colour | |
50 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
51 | ||
52 | #if wxUSE_PALETTE | |
53 | // create the mask from bitmap pixels with the given palette index | |
54 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
55 | #endif // wxUSE_PALETTE | |
56 | ||
57 | // create the mask from the given mono bitmap | |
58 | bool Create(const wxBitmap& bitmap); | |
59 | ||
60 | protected: | |
61 | // this function is called from Create() to free the existing mask data | |
62 | virtual void FreeData() = 0; | |
63 | ||
64 | // these functions must be overridden to implement the corresponding public | |
65 | // Create() methods, they shouldn't call FreeData() as it's already called | |
66 | // by the public wrappers | |
67 | virtual bool InitFromColour(const wxBitmap& bitmap, | |
68 | const wxColour& colour) = 0; | |
69 | virtual bool InitFromMonoBitmap(const wxBitmap& bitmap) = 0; | |
70 | }; | |
71 | ||
d22004c4 | 72 | #if defined(__WXMGL__) || \ |
b3c86150 | 73 | defined(__WXDFB__) || \ |
d22004c4 | 74 | defined(__WXMAC__) || \ |
4611dd06 | 75 | defined(__WXGTK__) || \ |
d22004c4 WS |
76 | defined(__WXCOCOA__) || \ |
77 | defined(__WXMOTIF__) || \ | |
78 | defined(__WXX11__) | |
91885f46 VZ |
79 | #define wxUSE_BITMAP_BASE 1 |
80 | #else | |
81 | #define wxUSE_BITMAP_BASE 0 | |
82 | #endif | |
83 | ||
a6a193a0 | 84 | // Only used by some ports |
b496583b | 85 | // FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes |
91885f46 | 86 | #if wxUSE_BITMAP_BASE |
b496583b | 87 | |
1e6feb95 VZ |
88 | // ---------------------------------------------------------------------------- |
89 | // wxBitmapHandler: class which knows how to create/load/save bitmaps in | |
90 | // different formats | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | class WXDLLEXPORT wxBitmapHandlerBase : public wxObject | |
94 | { | |
95 | public: | |
96 | wxBitmapHandlerBase() | |
7ee31b00 GD |
97 | : m_name() |
98 | , m_extension() | |
99 | , m_type(wxBITMAP_TYPE_INVALID) | |
100 | { } | |
1e6feb95 VZ |
101 | |
102 | virtual ~wxBitmapHandlerBase() { } | |
103 | ||
104 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, | |
105 | int width, int height, int depth = 1) = 0; | |
106 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
107 | int desiredWidth, int desiredHeight) = 0; | |
108 | virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, | |
109 | int type, const wxPalette *palette = NULL) = 0; | |
110 | ||
4b61c88d RR |
111 | void SetName(const wxString& name) { m_name = name; } |
112 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
113 | void SetType(wxBitmapType type) { m_type = type; } | |
114 | wxString GetName() const { return m_name; } | |
115 | wxString GetExtension() const { return m_extension; } | |
116 | wxBitmapType GetType() const { return m_type; } | |
117 | ||
118 | private: | |
1e6feb95 VZ |
119 | wxString m_name; |
120 | wxString m_extension; | |
121 | wxBitmapType m_type; | |
122 | ||
4b61c88d | 123 | private: |
1e6feb95 VZ |
124 | DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase) |
125 | }; | |
126 | ||
1e6feb95 VZ |
127 | class WXDLLEXPORT wxBitmapBase : public wxGDIObject |
128 | { | |
129 | public: | |
1e6feb95 VZ |
130 | /* |
131 | Derived class must implement these: | |
132 | ||
133 | wxBitmap(); | |
134 | wxBitmap(int width, int height, int depth = -1); | |
135 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
136 | wxBitmap(const char **bits); | |
137 | wxBitmap(char **bits); | |
1e6feb95 VZ |
138 | wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM); |
139 | wxBitmap(const wxImage& image, int depth = -1); | |
1e6feb95 VZ |
140 | bool operator == (const wxBitmap& bmp) const; |
141 | bool operator != (const wxBitmap& bmp) const; | |
142 | ||
143 | bool Create(int width, int height, int depth = -1); | |
144 | ||
145 | static void InitStandardHandlers(); | |
146 | */ | |
147 | ||
148 | virtual bool Ok() const = 0; | |
149 | ||
150 | virtual int GetHeight() const = 0; | |
151 | virtual int GetWidth() const = 0; | |
152 | virtual int GetDepth() const = 0; | |
153 | ||
154 | virtual wxImage ConvertToImage() const = 0; | |
155 | ||
156 | virtual wxMask *GetMask() const = 0; | |
157 | virtual void SetMask(wxMask *mask) = 0; | |
158 | ||
159 | virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0; | |
160 | ||
161 | virtual bool SaveFile(const wxString &name, wxBitmapType type, | |
162 | const wxPalette *palette = (wxPalette *)NULL) const = 0; | |
163 | virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0; | |
164 | ||
f28e099e VZ |
165 | /* |
166 | If raw bitmap access is supported (see wx/rawbmp.h), the following | |
167 | methods should be implemented: | |
168 | ||
169 | virtual bool GetRawData(wxRawBitmapData *data) = 0; | |
170 | virtual void UngetRawData(wxRawBitmapData *data) = 0; | |
171 | */ | |
172 | ||
173 | #if wxUSE_PALETTE | |
1e6feb95 VZ |
174 | virtual wxPalette *GetPalette() const = 0; |
175 | virtual void SetPalette(const wxPalette& palette) = 0; | |
f28e099e | 176 | #endif // wxUSE_PALETTE |
1e6feb95 | 177 | |
1e6feb95 VZ |
178 | // copies the contents and mask of the given (colour) icon to the bitmap |
179 | virtual bool CopyFromIcon(const wxIcon& icon) = 0; | |
180 | ||
181 | // implementation: | |
182 | virtual void SetHeight(int height) = 0; | |
183 | virtual void SetWidth(int width) = 0; | |
184 | virtual void SetDepth(int depth) = 0; | |
185 | ||
186 | // Format handling | |
187 | static inline wxList& GetHandlers() { return sm_handlers; } | |
188 | static void AddHandler(wxBitmapHandlerBase *handler); | |
189 | static void InsertHandler(wxBitmapHandlerBase *handler); | |
190 | static bool RemoveHandler(const wxString& name); | |
191 | static wxBitmapHandler *FindHandler(const wxString& name); | |
192 | static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType); | |
193 | static wxBitmapHandler *FindHandler(wxBitmapType bitmapType); | |
194 | ||
195 | //static void InitStandardHandlers(); | |
196 | // (wxBitmap must implement this one) | |
197 | ||
198 | static void CleanUpHandlers(); | |
199 | ||
87f83ac8 VZ |
200 | // this method is only used by the generic implementation of wxMask |
201 | // currently but could be useful elsewhere in the future: it can be | |
202 | // overridden to quantize the colour to correspond to bitmap colour depth | |
203 | // if necessary; default implementation simply returns the colour as is | |
204 | virtual wxColour QuantizeColour(const wxColour& colour) const | |
205 | { | |
206 | return colour; | |
207 | } | |
208 | ||
1e6feb95 VZ |
209 | protected: |
210 | static wxList sm_handlers; | |
211 | ||
212 | DECLARE_ABSTRACT_CLASS(wxBitmapBase) | |
213 | }; | |
91885f46 VZ |
214 | |
215 | #endif // wxUSE_BITMAP_BASE | |
1e6feb95 | 216 | |
4055ed82 | 217 | #if defined(__WXPALMOS__) |
91885f46 | 218 | #include "wx/palmos/bitmap.h" |
ffecfa5a | 219 | #elif defined(__WXMSW__) |
91885f46 | 220 | #include "wx/msw/bitmap.h" |
2049ba38 | 221 | #elif defined(__WXMOTIF__) |
91885f46 | 222 | #include "wx/x11/bitmap.h" |
1be7a35c | 223 | #elif defined(__WXGTK20__) |
91885f46 | 224 | #include "wx/gtk/bitmap.h" |
1be7a35c | 225 | #elif defined(__WXGTK__) |
91885f46 | 226 | #include "wx/gtk1/bitmap.h" |
83df96d6 | 227 | #elif defined(__WXX11__) |
91885f46 | 228 | #include "wx/x11/bitmap.h" |
1e6feb95 | 229 | #elif defined(__WXMGL__) |
91885f46 | 230 | #include "wx/mgl/bitmap.h" |
b3c86150 | 231 | #elif defined(__WXDFB__) |
91885f46 | 232 | #include "wx/dfb/bitmap.h" |
34138703 | 233 | #elif defined(__WXMAC__) |
91885f46 | 234 | #include "wx/mac/bitmap.h" |
fed66a87 | 235 | #elif defined(__WXCOCOA__) |
91885f46 | 236 | #include "wx/cocoa/bitmap.h" |
1777b9bb | 237 | #elif defined(__WXPM__) |
91885f46 | 238 | #include "wx/os2/bitmap.h" |
c801d85f KB |
239 | #endif |
240 | ||
87f83ac8 VZ |
241 | // we must include generic mask.h after wxBitmap definition |
242 | #if defined(__WXMGL__) || defined(__WXDFB__) | |
243 | #define wxUSE_GENERIC_MASK 1 | |
244 | #else | |
245 | #define wxUSE_GENERIC_MASK 0 | |
246 | #endif | |
247 | ||
248 | #if wxUSE_GENERIC_MASK | |
249 | #include "wx/generic/mask.h" | |
250 | #endif | |
251 | ||
91885f46 | 252 | #endif // _WX_BITMAP_H_BASE_ |