]> git.saurik.com Git - wxWidgets.git/blame - include/wx/bitmap.h
Fix missing documentation for several GDI functions.
[wxWidgets.git] / include / wx / bitmap.h
CommitLineData
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 19#include "wx/string.h"
22bd9387 20#include "wx/gdicmn.h" // for wxBitmapType
acb53ea5 21#include "wx/colour.h"
ac04aa99 22#include "wx/image.h"
1e6feb95 23
b5dbe15d
VS
24class WXDLLIMPEXP_FWD_CORE wxBitmap;
25class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
26class WXDLLIMPEXP_FWD_CORE wxIcon;
b5dbe15d
VS
27class WXDLLIMPEXP_FWD_CORE wxMask;
28class WXDLLIMPEXP_FWD_CORE wxPalette;
a85ccd79 29class WXDLLIMPEXP_FWD_CORE wxDC;
1e6feb95 30
6f5d7825
RR
31// ----------------------------------------------------------------------------
32// wxVariant support
33// ----------------------------------------------------------------------------
34
35#if wxUSE_VARIANT
36#include "wx/variant.h"
53a2db12 37DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLIMPEXP_CORE)
6f5d7825
RR
38#endif
39
87f83ac8
VZ
40// ----------------------------------------------------------------------------
41// wxMask represents the transparent area of the bitmap
42// ----------------------------------------------------------------------------
43
e86f2cc8
FM
44// TODO: all implementation of wxMask, except the generic one,
45// do not derive from wxMaskBase,,, they should
53a2db12 46class WXDLLIMPEXP_CORE wxMaskBase : public wxObject
87f83ac8
VZ
47{
48public:
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
60protected:
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
0e1f8ea4 72#if defined(__WXDFB__) || \
d22004c4 73 defined(__WXMAC__) || \
4611dd06 74 defined(__WXGTK__) || \
d22004c4
WS
75 defined(__WXCOCOA__) || \
76 defined(__WXMOTIF__) || \
77 defined(__WXX11__)
91885f46
VZ
78 #define wxUSE_BITMAP_BASE 1
79#else
80 #define wxUSE_BITMAP_BASE 0
81#endif
82
e86f2cc8
FM
83// a more readable way to tell
84#define wxBITMAP_SCREEN_DEPTH (-1)
85
86
20e6714a
VZ
87// ----------------------------------------------------------------------------
88// wxBitmapHelpers: container for various bitmap methods common to all ports.
89// ----------------------------------------------------------------------------
90
91// Unfortunately, currently wxBitmap does not inherit from wxBitmapBase on all
92// platforms and this is not easy to fix. So we extract at least some common
c3f641cb 93// methods into this class from which both wxBitmapBase (and hence wxBitmap on
20e6714a
VZ
94// all platforms where it does inherit from it) and wxBitmap in wxMSW and other
95// exceptional ports (only wxPM and old wxCocoa) inherit.
96class WXDLLIMPEXP_CORE wxBitmapHelpers
97{
98public:
99 // Create a new wxBitmap from the PNG data in the given buffer.
100 static wxBitmap NewFromPNGData(const void* data, size_t size);
101};
102
103
bd362275
VZ
104// All ports except wxMSW and wxOS2 use wxBitmapHandler and wxBitmapBase as
105// base class for wxBitmapHandler; wxMSW and wxOS2 use wxGDIImageHandler as
106// base class since it allows some code reuse there.
91885f46 107#if wxUSE_BITMAP_BASE
b496583b 108
1e6feb95
VZ
109// ----------------------------------------------------------------------------
110// wxBitmapHandler: class which knows how to create/load/save bitmaps in
111// different formats
112// ----------------------------------------------------------------------------
113
53a2db12 114class WXDLLIMPEXP_CORE wxBitmapHandler : public wxObject
1e6feb95
VZ
115{
116public:
e86f2cc8
FM
117 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
118 virtual ~wxBitmapHandler() { }
119
120 // NOTE: the following functions should be pure virtuals, but they aren't
121 // because otherwise almost all ports would have to implement
122 // them as "return false"...
1e6feb95 123
e86f2cc8
FM
124 virtual bool Create(wxBitmap *WXUNUSED(bitmap), const void* WXUNUSED(data),
125 wxBitmapType WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height),
126 int WXUNUSED(depth) = 1)
127 { return false; }
128
129 virtual bool LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
130 wxBitmapType WXUNUSED(type), int WXUNUSED(desiredWidth),
131 int WXUNUSED(desiredHeight))
132 { return false; }
133
134 virtual bool SaveFile(const wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
135 wxBitmapType WXUNUSED(type), const wxPalette *WXUNUSED(palette) = NULL) const
136 { return false; }
1e6feb95 137
4b61c88d
RR
138 void SetName(const wxString& name) { m_name = name; }
139 void SetExtension(const wxString& ext) { m_extension = ext; }
140 void SetType(wxBitmapType type) { m_type = type; }
452418c4
PC
141 const wxString& GetName() const { return m_name; }
142 const wxString& GetExtension() const { return m_extension; }
4b61c88d
RR
143 wxBitmapType GetType() const { return m_type; }
144
145private:
1e6feb95
VZ
146 wxString m_name;
147 wxString m_extension;
148 wxBitmapType m_type;
149
e86f2cc8 150 DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
1e6feb95
VZ
151};
152
e86f2cc8
FM
153// ----------------------------------------------------------------------------
154// wxBitmap: class which represents platform-dependent bitmap (unlike wxImage)
155// ----------------------------------------------------------------------------
156
20e6714a
VZ
157class WXDLLIMPEXP_CORE wxBitmapBase : public wxGDIObject,
158 public wxBitmapHelpers
1e6feb95
VZ
159{
160public:
1e6feb95
VZ
161 /*
162 Derived class must implement these:
163
164 wxBitmap();
e86f2cc8 165 wxBitmap(const wxBitmap& bmp);
1e6feb95 166 wxBitmap(const char bits[], int width, int height, int depth = 1);
e86f2cc8 167 wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
732d8c74 168 wxBitmap(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH);
452418c4 169 wxBitmap(const char* const* bits);
1e6feb95 170 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
e86f2cc8 171 wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
1e6feb95
VZ
172
173 static void InitStandardHandlers();
174 */
175
e86f2cc8 176 virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
732d8c74 177 virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
a066916b 178 virtual bool CreateScaled(int w, int h, int d, double logicalScale)
b5ec0c78 179 { return Create(w*logicalScale,h*logicalScale,d); }
e86f2cc8 180
1e6feb95
VZ
181 virtual int GetHeight() const = 0;
182 virtual int GetWidth() const = 0;
183 virtual int GetDepth() const = 0;
184
c74b07ac
FM
185 wxSize GetSize() const
186 { return wxSize(GetWidth(), GetHeight()); }
187
9afa58e3 188 // support for scaled bitmaps
a85ccd79
SC
189 virtual double GetScaleFactor() const { return 1.0; }
190 virtual double GetScaledWidth() const { return GetWidth() / GetScaleFactor(); }
191 virtual double GetScaledHeight() const { return GetHeight() / GetScaleFactor(); }
9afa58e3
SC
192 virtual wxSize GetScaledSize() const
193 { return wxSize(GetScaledWidth(), GetScaledHeight()); }
194
c0521644 195#if wxUSE_IMAGE
1e6feb95 196 virtual wxImage ConvertToImage() const = 0;
ac04aa99
VZ
197
198 // Convert to disabled (dimmed) bitmap.
199 wxBitmap ConvertToDisabled(unsigned char brightness = 255) const;
c0521644 200#endif // wxUSE_IMAGE
1e6feb95
VZ
201
202 virtual wxMask *GetMask() const = 0;
203 virtual void SetMask(wxMask *mask) = 0;
204
205 virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0;
206
207 virtual bool SaveFile(const wxString &name, wxBitmapType type,
d3b9f782 208 const wxPalette *palette = NULL) const = 0;
1e6feb95
VZ
209 virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0;
210
f28e099e
VZ
211 /*
212 If raw bitmap access is supported (see wx/rawbmp.h), the following
213 methods should be implemented:
214
215 virtual bool GetRawData(wxRawBitmapData *data) = 0;
216 virtual void UngetRawData(wxRawBitmapData *data) = 0;
217 */
218
219#if wxUSE_PALETTE
1e6feb95
VZ
220 virtual wxPalette *GetPalette() const = 0;
221 virtual void SetPalette(const wxPalette& palette) = 0;
f28e099e 222#endif // wxUSE_PALETTE
1e6feb95 223
1e6feb95
VZ
224 // copies the contents and mask of the given (colour) icon to the bitmap
225 virtual bool CopyFromIcon(const wxIcon& icon) = 0;
226
227 // implementation:
228 virtual void SetHeight(int height) = 0;
229 virtual void SetWidth(int width) = 0;
230 virtual void SetDepth(int depth) = 0;
231
232 // Format handling
233 static inline wxList& GetHandlers() { return sm_handlers; }
e86f2cc8
FM
234 static void AddHandler(wxBitmapHandler *handler);
235 static void InsertHandler(wxBitmapHandler *handler);
1e6feb95
VZ
236 static bool RemoveHandler(const wxString& name);
237 static wxBitmapHandler *FindHandler(const wxString& name);
238 static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType);
239 static wxBitmapHandler *FindHandler(wxBitmapType bitmapType);
240
241 //static void InitStandardHandlers();
242 // (wxBitmap must implement this one)
243
244 static void CleanUpHandlers();
245
87f83ac8
VZ
246 // this method is only used by the generic implementation of wxMask
247 // currently but could be useful elsewhere in the future: it can be
248 // overridden to quantize the colour to correspond to bitmap colour depth
249 // if necessary; default implementation simply returns the colour as is
250 virtual wxColour QuantizeColour(const wxColour& colour) const
251 {
252 return colour;
253 }
254
1e6feb95
VZ
255protected:
256 static wxList sm_handlers;
257
258 DECLARE_ABSTRACT_CLASS(wxBitmapBase)
259};
91885f46
VZ
260
261#endif // wxUSE_BITMAP_BASE
1e6feb95 262
cbea3ec6
FM
263
264// the wxBITMAP_DEFAULT_TYPE constant defines the default argument value
265// for wxBitmap's ctor and wxBitmap::LoadFile() functions.
bd362275 266#if defined(__WXMSW__)
cbea3ec6 267 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 268 #include "wx/msw/bitmap.h"
2049ba38 269#elif defined(__WXMOTIF__)
cbea3ec6 270 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 271 #include "wx/x11/bitmap.h"
1be7a35c 272#elif defined(__WXGTK20__)
327972e7
VZ
273 #ifdef __WINDOWS__
274 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
275 #else
276 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
277 #endif
91885f46 278 #include "wx/gtk/bitmap.h"
1be7a35c 279#elif defined(__WXGTK__)
cbea3ec6 280 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 281 #include "wx/gtk1/bitmap.h"
83df96d6 282#elif defined(__WXX11__)
cbea3ec6 283 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 284 #include "wx/x11/bitmap.h"
b3c86150 285#elif defined(__WXDFB__)
4ca8531f 286 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 287 #include "wx/dfb/bitmap.h"
34138703 288#elif defined(__WXMAC__)
cbea3ec6 289 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_PICT_RESOURCE
ef0e9220 290 #include "wx/osx/bitmap.h"
fed66a87 291#elif defined(__WXCOCOA__)
cbea3ec6 292 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 293 #include "wx/cocoa/bitmap.h"
1777b9bb 294#elif defined(__WXPM__)
cbea3ec6 295 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 296 #include "wx/os2/bitmap.h"
c801d85f
KB
297#endif
298
ac04aa99
VZ
299#if wxUSE_IMAGE
300inline
301wxBitmap
302#if wxUSE_BITMAP_BASE
303wxBitmapBase::
304#else
305wxBitmap::
306#endif
307ConvertToDisabled(unsigned char brightness) const
308{
309 return ConvertToImage().ConvertToDisabled(brightness);
310}
311#endif // wxUSE_IMAGE
312
87f83ac8 313// we must include generic mask.h after wxBitmap definition
0e1f8ea4 314#if defined(__WXDFB__)
87f83ac8
VZ
315 #define wxUSE_GENERIC_MASK 1
316#else
317 #define wxUSE_GENERIC_MASK 0
318#endif
319
320#if wxUSE_GENERIC_MASK
321 #include "wx/generic/mask.h"
322#endif
323
91885f46 324#endif // _WX_BITMAP_H_BASE_