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