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