]> git.saurik.com Git - wxWidgets.git/blame - include/wx/bitmap.h
Call Expand on an item's parent chain in EnsureVisible
[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"
1e6feb95 22
b5dbe15d
VS
23class WXDLLIMPEXP_FWD_CORE wxBitmap;
24class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
25class WXDLLIMPEXP_FWD_CORE wxIcon;
26class WXDLLIMPEXP_FWD_CORE wxImage;
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
d22004c4 71#if defined(__WXMGL__) || \
b3c86150 72 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
87// All ports except wxMSW,wxOS2,wxPalmOS use wxBitmapHandler and wxBitmapBase as base class
88// for wxBitmapHandler; wxMSW,wxOS2,wxPalmOS use wxGDIImageHandler as base class
89// since it allows some code reuse there.
91885f46 90#if wxUSE_BITMAP_BASE
b496583b 91
1e6feb95
VZ
92// ----------------------------------------------------------------------------
93// wxBitmapHandler: class which knows how to create/load/save bitmaps in
94// different formats
95// ----------------------------------------------------------------------------
96
53a2db12 97class WXDLLIMPEXP_CORE wxBitmapHandler : public wxObject
1e6feb95
VZ
98{
99public:
e86f2cc8
FM
100 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
101 virtual ~wxBitmapHandler() { }
102
103 // NOTE: the following functions should be pure virtuals, but they aren't
104 // because otherwise almost all ports would have to implement
105 // them as "return false"...
1e6feb95 106
e86f2cc8
FM
107 virtual bool Create(wxBitmap *WXUNUSED(bitmap), const void* WXUNUSED(data),
108 wxBitmapType WXUNUSED(type), int WXUNUSED(width), int WXUNUSED(height),
109 int WXUNUSED(depth) = 1)
110 { return false; }
111
112 virtual bool LoadFile(wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
113 wxBitmapType WXUNUSED(type), int WXUNUSED(desiredWidth),
114 int WXUNUSED(desiredHeight))
115 { return false; }
116
117 virtual bool SaveFile(const wxBitmap *WXUNUSED(bitmap), const wxString& WXUNUSED(name),
118 wxBitmapType WXUNUSED(type), const wxPalette *WXUNUSED(palette) = NULL) const
119 { return false; }
1e6feb95 120
4b61c88d
RR
121 void SetName(const wxString& name) { m_name = name; }
122 void SetExtension(const wxString& ext) { m_extension = ext; }
123 void SetType(wxBitmapType type) { m_type = type; }
452418c4
PC
124 const wxString& GetName() const { return m_name; }
125 const wxString& GetExtension() const { return m_extension; }
4b61c88d
RR
126 wxBitmapType GetType() const { return m_type; }
127
128private:
1e6feb95
VZ
129 wxString m_name;
130 wxString m_extension;
131 wxBitmapType m_type;
132
e86f2cc8 133 DECLARE_ABSTRACT_CLASS(wxBitmapHandler)
1e6feb95
VZ
134};
135
e86f2cc8
FM
136
137// ----------------------------------------------------------------------------
138// wxBitmap: class which represents platform-dependent bitmap (unlike wxImage)
139// ----------------------------------------------------------------------------
140
53a2db12 141class WXDLLIMPEXP_CORE wxBitmapBase : public wxGDIObject
1e6feb95
VZ
142{
143public:
1e6feb95
VZ
144 /*
145 Derived class must implement these:
146
147 wxBitmap();
e86f2cc8 148 wxBitmap(const wxBitmap& bmp);
1e6feb95 149 wxBitmap(const char bits[], int width, int height, int depth = 1);
e86f2cc8 150 wxBitmap(int width, int height, 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
FM
158 virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) = 0;
159
1e6feb95
VZ
160 virtual int GetHeight() const = 0;
161 virtual int GetWidth() const = 0;
162 virtual int GetDepth() const = 0;
163
c74b07ac
FM
164 wxSize GetSize() const
165 { return wxSize(GetWidth(), GetHeight()); }
166
c0521644 167#if wxUSE_IMAGE
1e6feb95 168 virtual wxImage ConvertToImage() const = 0;
c0521644 169#endif // wxUSE_IMAGE
1e6feb95
VZ
170
171 virtual wxMask *GetMask() const = 0;
172 virtual void SetMask(wxMask *mask) = 0;
173
174 virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0;
175
176 virtual bool SaveFile(const wxString &name, wxBitmapType type,
177 const wxPalette *palette = (wxPalette *)NULL) const = 0;
178 virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0;
179
f28e099e
VZ
180 /*
181 If raw bitmap access is supported (see wx/rawbmp.h), the following
182 methods should be implemented:
183
184 virtual bool GetRawData(wxRawBitmapData *data) = 0;
185 virtual void UngetRawData(wxRawBitmapData *data) = 0;
186 */
187
188#if wxUSE_PALETTE
1e6feb95
VZ
189 virtual wxPalette *GetPalette() const = 0;
190 virtual void SetPalette(const wxPalette& palette) = 0;
f28e099e 191#endif // wxUSE_PALETTE
1e6feb95 192
1e6feb95
VZ
193 // copies the contents and mask of the given (colour) icon to the bitmap
194 virtual bool CopyFromIcon(const wxIcon& icon) = 0;
195
196 // implementation:
197 virtual void SetHeight(int height) = 0;
198 virtual void SetWidth(int width) = 0;
199 virtual void SetDepth(int depth) = 0;
200
201 // Format handling
202 static inline wxList& GetHandlers() { return sm_handlers; }
e86f2cc8
FM
203 static void AddHandler(wxBitmapHandler *handler);
204 static void InsertHandler(wxBitmapHandler *handler);
1e6feb95
VZ
205 static bool RemoveHandler(const wxString& name);
206 static wxBitmapHandler *FindHandler(const wxString& name);
207 static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType);
208 static wxBitmapHandler *FindHandler(wxBitmapType bitmapType);
209
210 //static void InitStandardHandlers();
211 // (wxBitmap must implement this one)
212
213 static void CleanUpHandlers();
214
87f83ac8
VZ
215 // this method is only used by the generic implementation of wxMask
216 // currently but could be useful elsewhere in the future: it can be
217 // overridden to quantize the colour to correspond to bitmap colour depth
218 // if necessary; default implementation simply returns the colour as is
219 virtual wxColour QuantizeColour(const wxColour& colour) const
220 {
221 return colour;
222 }
223
1e6feb95
VZ
224protected:
225 static wxList sm_handlers;
226
227 DECLARE_ABSTRACT_CLASS(wxBitmapBase)
228};
91885f46
VZ
229
230#endif // wxUSE_BITMAP_BASE
1e6feb95 231
cbea3ec6
FM
232
233// the wxBITMAP_DEFAULT_TYPE constant defines the default argument value
234// for wxBitmap's ctor and wxBitmap::LoadFile() functions.
4055ed82 235#if defined(__WXPALMOS__)
cbea3ec6 236 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 237 #include "wx/palmos/bitmap.h"
ffecfa5a 238#elif defined(__WXMSW__)
cbea3ec6 239 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 240 #include "wx/msw/bitmap.h"
2049ba38 241#elif defined(__WXMOTIF__)
cbea3ec6 242 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 243 #include "wx/x11/bitmap.h"
1be7a35c 244#elif defined(__WXGTK20__)
cbea3ec6 245 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 246 #include "wx/gtk/bitmap.h"
1be7a35c 247#elif defined(__WXGTK__)
cbea3ec6 248 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 249 #include "wx/gtk1/bitmap.h"
83df96d6 250#elif defined(__WXX11__)
cbea3ec6 251 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_XPM
91885f46 252 #include "wx/x11/bitmap.h"
1e6feb95 253#elif defined(__WXMGL__)
cbea3ec6 254 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_RESOURCE
91885f46 255 #include "wx/mgl/bitmap.h"
b3c86150 256#elif defined(__WXDFB__)
cbea3ec6 257 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_RESOURCE
91885f46 258 #include "wx/dfb/bitmap.h"
34138703 259#elif defined(__WXMAC__)
cbea3ec6 260 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_PICT_RESOURCE
ef0e9220 261 #include "wx/osx/bitmap.h"
fed66a87 262#elif defined(__WXCOCOA__)
cbea3ec6 263 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 264 #include "wx/cocoa/bitmap.h"
1777b9bb 265#elif defined(__WXPM__)
cbea3ec6 266 #define wxBITMAP_DEFAULT_TYPE wxBITMAP_TYPE_BMP_RESOURCE
91885f46 267 #include "wx/os2/bitmap.h"
c801d85f
KB
268#endif
269
87f83ac8
VZ
270// we must include generic mask.h after wxBitmap definition
271#if defined(__WXMGL__) || defined(__WXDFB__)
272 #define wxUSE_GENERIC_MASK 1
273#else
274 #define wxUSE_GENERIC_MASK 0
275#endif
276
277#if wxUSE_GENERIC_MASK
278 #include "wx/generic/mask.h"
279#endif
280
91885f46 281#endif // _WX_BITMAP_H_BASE_