]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/bitmap.h
put grid string in generic/grid.cpp, not common/datacmn.cpp
[wxWidgets.git] / include / wx / bitmap.h
... / ...
CommitLineData
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$
8// Copyright: (c) wxWidgets team
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_BITMAP_H_BASE_
13#define _WX_BITMAP_H_BASE_
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#include "wx/defs.h"
20#include "wx/object.h"
21#include "wx/string.h"
22#include "wx/gdiobj.h"
23#include "wx/gdicmn.h" // for wxBitmapType
24#include "wx/colour.h"
25
26class WXDLLEXPORT wxBitmap;
27class WXDLLEXPORT wxBitmapHandler;
28class WXDLLEXPORT wxIcon;
29class WXDLLEXPORT wxImage;
30class WXDLLEXPORT wxMask;
31class WXDLLEXPORT wxPalette;
32
33// ----------------------------------------------------------------------------
34// wxVariant support
35// ----------------------------------------------------------------------------
36
37#if wxUSE_VARIANT
38#include "wx/variant.h"
39DECLARE_VARIANT_OBJECT_EXPORTED(wxBitmap,WXDLLEXPORT)
40#endif
41
42// ----------------------------------------------------------------------------
43// wxMask represents the transparent area of the bitmap
44// ----------------------------------------------------------------------------
45
46class WXDLLEXPORT wxMaskBase : public wxObject
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
72#if defined(__WXMGL__) || \
73 defined(__WXDFB__) || \
74 defined(__WXMAC__) || \
75 defined(__WXGTK__) || \
76 defined(__WXCOCOA__) || \
77 defined(__WXMOTIF__) || \
78 defined(__WXX11__)
79 #define wxUSE_BITMAP_BASE 1
80#else
81 #define wxUSE_BITMAP_BASE 0
82#endif
83
84// Only used by some ports
85// FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
86#if wxUSE_BITMAP_BASE
87
88// ----------------------------------------------------------------------------
89// wxBitmapHandler: class which knows how to create/load/save bitmaps in
90// different formats
91// ----------------------------------------------------------------------------
92
93class WXDLLEXPORT wxBitmapHandlerBase : public wxObject
94{
95public:
96 wxBitmapHandlerBase()
97 : m_name()
98 , m_extension()
99 , m_type(wxBITMAP_TYPE_INVALID)
100 { }
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
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
118private:
119 wxString m_name;
120 wxString m_extension;
121 wxBitmapType m_type;
122
123private:
124 DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase)
125};
126
127class WXDLLEXPORT wxBitmapBase : public wxGDIObject
128{
129public:
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);
138 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
139 wxBitmap(const wxImage& image, int depth = -1);
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
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
174 virtual wxPalette *GetPalette() const = 0;
175 virtual void SetPalette(const wxPalette& palette) = 0;
176#endif // wxUSE_PALETTE
177
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
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
209protected:
210 static wxList sm_handlers;
211
212 DECLARE_ABSTRACT_CLASS(wxBitmapBase)
213};
214
215#endif // wxUSE_BITMAP_BASE
216
217#if defined(__WXPALMOS__)
218 #include "wx/palmos/bitmap.h"
219#elif defined(__WXMSW__)
220 #include "wx/msw/bitmap.h"
221#elif defined(__WXMOTIF__)
222 #include "wx/x11/bitmap.h"
223#elif defined(__WXGTK20__)
224 #include "wx/gtk/bitmap.h"
225#elif defined(__WXGTK__)
226 #include "wx/gtk1/bitmap.h"
227#elif defined(__WXX11__)
228 #include "wx/x11/bitmap.h"
229#elif defined(__WXMGL__)
230 #include "wx/mgl/bitmap.h"
231#elif defined(__WXDFB__)
232 #include "wx/dfb/bitmap.h"
233#elif defined(__WXMAC__)
234 #include "wx/mac/bitmap.h"
235#elif defined(__WXCOCOA__)
236 #include "wx/cocoa/bitmap.h"
237#elif defined(__WXPM__)
238 #include "wx/os2/bitmap.h"
239#endif
240
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
252#endif // _WX_BITMAP_H_BASE_