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