1
///////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxBitmap class interface
4
// Author: Vaclav Slavik
7
// RCS-ID: $Id: bitmap.h 71889 2012-06-30 16:33:23Z VZ $
8
// Copyright: (c) wxWidgets team
9
// Licence: wxWindows licence
10
///////////////////////////////////////////////////////////////////////////////
12
#ifndef _WX_BITMAP_H_BASE_
13
#define _WX_BITMAP_H_BASE_
15
// ----------------------------------------------------------------------------
17
// ----------------------------------------------------------------------------
19
#include "wx/string.h"
20
#include "wx/gdicmn.h" // for wxBitmapType
21
#include "wx/colour.h"
24
class WXDLLIMPEXP_FWD_CORE wxBitmap;
25
class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
26
class WXDLLIMPEXP_FWD_CORE wxIcon;
27
class WXDLLIMPEXP_FWD_CORE wxMask;
28
class WXDLLIMPEXP_FWD_CORE wxPalette;
30
// ----------------------------------------------------------------------------
32
// ----------------------------------------------------------------------------
35
#include "wx/variant.h"
36
DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLIMPEXP_CORE)
39
// ----------------------------------------------------------------------------
40
// wxMask represents the transparent area of the bitmap
41
// ----------------------------------------------------------------------------
43
// TODO: all implementation of wxMask, except the generic one,
44
// do not derive from wxMaskBase,,, they should
45
class WXDLLIMPEXP_CORE wxMaskBase : public wxObject
48
// create the mask from bitmap pixels of the given colour
49
bool Create(const wxBitmap& bitmap, const wxColour& colour);
52
// create the mask from bitmap pixels with the given palette index
53
bool Create(const wxBitmap& bitmap, int paletteIndex);
54
#endif // wxUSE_PALETTE
56
// create the mask from the given mono bitmap
57
bool Create(const wxBitmap& bitmap);
60
// this function is called from Create() to free the existing mask data
61
virtual void FreeData() = 0;
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;
71
#if defined(__WXDFB__) || \
72
defined(__WXMAC__) || \
73
defined(__WXGTK__) || \
74
defined(__WXCOCOA__) || \
75
defined(__WXMOTIF__) || \
77
#define wxUSE_BITMAP_BASE 1
79
#define wxUSE_BITMAP_BASE 0
82
// a more readable way to tell
83
#define wxBITMAP_SCREEN_DEPTH (-1)
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.
91
// ----------------------------------------------------------------------------
92
// wxBitmapHandler: class which knows how to create/load/save bitmaps in
94
// ----------------------------------------------------------------------------
96
class WXDLLIMPEXP_CORE wxBitmapHandler : public wxObject
99
wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
100
virtual ~wxBitmapHandler() { }
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"...
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)
111
virtual bool LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
112
wxBitmapType WXUNUSED(type), int WXUNUSED(desiredWidth),
113
int WXUNUSED(desiredHeight))
116
virtual bool SaveFile(const wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
117
wxBitmapType WXUNUSED(type), const wxPalette *WXUNUSED(palette) = NULL) const
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; }
123
const wxString& GetName() const { return m_name; }
124
const wxString& GetExtension() const { return m_extension; }
125
wxBitmapType GetType() const { return m_type; }
129
wxString m_extension;
132
DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
136
// ----------------------------------------------------------------------------
137
// wxBitmap: class which represents platform-dependent bitmap (unlike wxImage)
138
// ----------------------------------------------------------------------------
140
class WXDLLIMPEXP_CORE wxBitmapBase : public wxGDIObject
144
Derived class must implement these:
147
wxBitmap(const wxBitmap& bmp);
148
wxBitmap(const char bits[], int width, int height, int depth = 1);
149
wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
150
wxBitmap(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH);
151
wxBitmap(const char* const* bits);
152
wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
153
wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
155
static void InitStandardHandlers();
158
virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
159
virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
161
virtual int GetHeight() const = 0;
162
virtual int GetWidth() const = 0;
163
virtual int GetDepth() const = 0;
165
wxSize GetSize() const
166
{ return wxSize(GetWidth(), GetHeight()); }
169
virtual wxImage ConvertToImage() const = 0;
171
// Convert to disabled (dimmed) bitmap.
172
wxBitmap ConvertToDisabled(unsigned char brightness = 255) const;
173
#endif // wxUSE_IMAGE
175
virtual wxMask *GetMask() const = 0;
176
virtual void SetMask(wxMask *mask) = 0;
178
virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0;
180
virtual bool SaveFile(const wxString &name, wxBitmapType type,
181
const wxPalette *palette = NULL) const = 0;
182
virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0;
185
If raw bitmap access is supported (see wx/rawbmp.h), the following
186
methods should be implemented:
188
virtual bool GetRawData(wxRawBitmapData *data) = 0;
189
virtual void UngetRawData(wxRawBitmapData *data) = 0;
193
virtual wxPalette *GetPalette() const = 0;
194
virtual void SetPalette(const wxPalette& palette) = 0;
195
#endif // wxUSE_PALETTE
197
// copies the contents and mask of the given (colour) icon to the bitmap
198
virtual bool CopyFromIcon(const wxIcon& icon) = 0;
201
virtual void SetHeight(int height) = 0;
202
virtual void SetWidth(int width) = 0;
203
virtual void SetDepth(int depth) = 0;
206
static inline wxList& GetHandlers() { return sm_handlers; }
207
static void AddHandler(wxBitmapHandler *handler);
208
static void InsertHandler(wxBitmapHandler *handler);
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);
214
//static void InitStandardHandlers();
215
// (wxBitmap must implement this one)
217
static void CleanUpHandlers();
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
229
static wxList sm_handlers;
231
DECLARE_ABSTRACT_CLASS(wxBitmapBase)
234
#endif // wxUSE_BITMAP_BASE
237
// the wxBITMAP_DEFAULT_TYPE constant defines the default argument value
238
// for wxBitmap's ctor and wxBitmap::LoadFile() functions.
239
#if defined(__WXMSW__)
240
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
241
#include "wx/msw/bitmap.h"
242
#elif defined(__WXMOTIF__)
243
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
244
#include "wx/x11/bitmap.h"
245
#elif defined(__WXGTK20__)
247
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
249
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
251
#include "wx/gtk/bitmap.h"
252
#elif defined(__WXGTK__)
253
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
254
#include "wx/gtk1/bitmap.h"
255
#elif defined(__WXX11__)
256
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
257
#include "wx/x11/bitmap.h"
258
#elif defined(__WXDFB__)
259
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
260
#include "wx/dfb/bitmap.h"
261
#elif defined(__WXMAC__)
262
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_PICT_RESOURCE
263
#include "wx/osx/bitmap.h"
264
#elif defined(__WXCOCOA__)
265
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
266
#include "wx/cocoa/bitmap.h"
267
#elif defined(__WXPM__)
268
#define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
269
#include "wx/os2/bitmap.h"
275
#if wxUSE_BITMAP_BASE
280
ConvertToDisabled(unsigned char brightness) const
282
return ConvertToImage().ConvertToDisabled(brightness);
284
#endif // wxUSE_IMAGE
286
// we must include generic mask.h after wxBitmap definition
287
#if defined(__WXDFB__)
288
#define wxUSE_GENERIC_MASK 1
290
#define wxUSE_GENERIC_MASK 0
293
#if wxUSE_GENERIC_MASK
294
#include "wx/generic/mask.h"
297
#endif // _WX_BITMAP_H_BASE_