]> git.saurik.com Git - wxWidgets.git/blob - include/wx/bitmap.h
f5f6b51ceb96258385415090ba51d8108ebc24d6
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "bitmapbase.h"
21 #endif
22
23 #include "wx/defs.h"
24 #include "wx/object.h"
25 #include "wx/string.h"
26 #include "wx/gdiobj.h"
27 #include "wx/gdicmn.h" // for wxBitmapType
28
29 class WXDLLEXPORT wxBitmap;
30 class WXDLLEXPORT wxBitmapHandler;
31 class WXDLLEXPORT wxImage;
32 class WXDLLEXPORT wxMask;
33 class WXDLLEXPORT wxPalette;
34
35 #if defined(__WXMGL__) || \
36 defined(__WXMAC__) || \
37 defined(__WXGTK__) || \
38 defined(__WXCOCOA__) || \
39 defined(__WXMOTIF__) || \
40 defined(__WXX11__)
41 // Only used by some ports
42 // FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
43
44 // ----------------------------------------------------------------------------
45 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
46 // different formats
47 // ----------------------------------------------------------------------------
48
49 class WXDLLEXPORT wxBitmapHandlerBase : public wxObject
50 {
51 public:
52 wxBitmapHandlerBase()
53 : m_name()
54 , m_extension()
55 , m_type(wxBITMAP_TYPE_INVALID)
56 { }
57
58 virtual ~wxBitmapHandlerBase() { }
59
60 virtual bool Create(wxBitmap *bitmap, void *data, long flags,
61 int width, int height, int depth = 1) = 0;
62 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
63 int desiredWidth, int desiredHeight) = 0;
64 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name,
65 int type, const wxPalette *palette = NULL) = 0;
66
67 void SetName(const wxString& name) { m_name = name; }
68 void SetExtension(const wxString& ext) { m_extension = ext; }
69 void SetType(wxBitmapType type) { m_type = type; }
70 wxString GetName() const { return m_name; }
71 wxString GetExtension() const { return m_extension; }
72 wxBitmapType GetType() const { return m_type; }
73
74 protected:
75 wxString m_name;
76 wxString m_extension;
77 wxBitmapType m_type;
78
79 DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase)
80 };
81
82 class WXDLLEXPORT wxBitmapBase : public wxGDIObject
83 {
84 public:
85 wxBitmapBase() : wxGDIObject() {}
86 virtual ~wxBitmapBase() {}
87
88 /*
89 Derived class must implement these:
90
91 wxBitmap();
92 wxBitmap(int width, int height, int depth = -1);
93 wxBitmap(const char bits[], int width, int height, int depth = 1);
94 wxBitmap(const char **bits);
95 wxBitmap(char **bits);
96 wxBitmap(const wxBitmap& bmp);
97 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
98 wxBitmap(const wxImage& image, int depth = -1);
99 wxBitmap& operator = (const wxBitmap& bmp);
100 bool operator == (const wxBitmap& bmp) const;
101 bool operator != (const wxBitmap& bmp) const;
102
103 bool Create(int width, int height, int depth = -1);
104
105 static void InitStandardHandlers();
106 */
107
108 virtual bool Ok() const = 0;
109
110 virtual int GetHeight() const = 0;
111 virtual int GetWidth() const = 0;
112 virtual int GetDepth() const = 0;
113
114 virtual wxImage ConvertToImage() const = 0;
115
116 virtual wxMask *GetMask() const = 0;
117 virtual void SetMask(wxMask *mask) = 0;
118
119 virtual wxBitmap GetSubBitmap(const wxRect& rect) const = 0;
120
121 virtual bool SaveFile(const wxString &name, wxBitmapType type,
122 const wxPalette *palette = (wxPalette *)NULL) const = 0;
123 virtual bool LoadFile(const wxString &name, wxBitmapType type) = 0;
124
125 /*
126 If raw bitmap access is supported (see wx/rawbmp.h), the following
127 methods should be implemented:
128
129 virtual bool GetRawData(wxRawBitmapData *data) = 0;
130 virtual void UngetRawData(wxRawBitmapData *data) = 0;
131 */
132
133 #if wxUSE_PALETTE
134 virtual wxPalette *GetPalette() const = 0;
135 virtual void SetPalette(const wxPalette& palette) = 0;
136 #endif // wxUSE_PALETTE
137
138 // copies the contents and mask of the given (colour) icon to the bitmap
139 virtual bool CopyFromIcon(const wxIcon& icon) = 0;
140
141 // implementation:
142 virtual void SetHeight(int height) = 0;
143 virtual void SetWidth(int width) = 0;
144 virtual void SetDepth(int depth) = 0;
145
146 // Format handling
147 static inline wxList& GetHandlers() { return sm_handlers; }
148 static void AddHandler(wxBitmapHandlerBase *handler);
149 static void InsertHandler(wxBitmapHandlerBase *handler);
150 static bool RemoveHandler(const wxString& name);
151 static wxBitmapHandler *FindHandler(const wxString& name);
152 static wxBitmapHandler *FindHandler(const wxString& extension, wxBitmapType bitmapType);
153 static wxBitmapHandler *FindHandler(wxBitmapType bitmapType);
154
155 //static void InitStandardHandlers();
156 // (wxBitmap must implement this one)
157
158 static void CleanUpHandlers();
159
160 protected:
161 static wxList sm_handlers;
162
163 DECLARE_ABSTRACT_CLASS(wxBitmapBase)
164 };
165 #endif
166
167 #if defined(__WXPALMOS__)
168 #include "wx/palmos/bitmap.h"
169 #elif defined(__WXMSW__)
170 #include "wx/msw/bitmap.h"
171 #elif defined(__WXMOTIF__)
172 #include "wx/x11/bitmap.h"
173 #elif defined(__WXGTK__)
174 #include "wx/gtk/bitmap.h"
175 #elif defined(__WXX11__)
176 #include "wx/x11/bitmap.h"
177 #elif defined(__WXMGL__)
178 #include "wx/mgl/bitmap.h"
179 #elif defined(__WXMAC__)
180 #include "wx/mac/bitmap.h"
181 #elif defined(__WXCOCOA__)
182 #include "wx/cocoa/bitmap.h"
183 #elif defined(__WXPM__)
184 #include "wx/os2/bitmap.h"
185 #endif
186
187 #endif
188 // _WX_BITMAP_H_BASE_