]>
Commit | Line | Data |
---|---|---|
83df96d6 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bitmap.h | |
3 | // Purpose: wxBitmap class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_BITMAP_H_ | |
13 | #define _WX_BITMAP_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "bitmap.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/gdiobj.h" | |
20 | #include "wx/gdicmn.h" | |
21 | #include "wx/palette.h" | |
22 | ||
23 | // Bitmap | |
24 | class WXDLLEXPORT wxDC; | |
25 | class WXDLLEXPORT wxControl; | |
26 | class WXDLLEXPORT wxBitmap; | |
27 | class WXDLLEXPORT wxBitmapHandler; | |
28 | class WXDLLEXPORT wxIcon; | |
29 | class WXDLLEXPORT wxCursor; | |
30 | class WXDLLEXPORT wxImage; | |
31 | ||
32 | // A mask is a mono bitmap used for drawing bitmaps | |
33 | // transparently. | |
34 | class WXDLLEXPORT wxMask: public wxObject | |
35 | { | |
36 | DECLARE_DYNAMIC_CLASS(wxMask) | |
37 | ||
38 | public: | |
39 | wxMask(); | |
40 | ||
41 | // Construct a mask from a bitmap and a colour indicating | |
42 | // the transparent area | |
43 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
44 | ||
45 | // Construct a mask from a bitmap and a palette index indicating | |
46 | // the transparent area | |
47 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
48 | ||
49 | // Construct a mask from a mono bitmap (copies the bitmap). | |
50 | wxMask(const wxBitmap& bitmap); | |
51 | ||
52 | ~wxMask(); | |
53 | ||
54 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
55 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
56 | bool Create(const wxBitmap& bitmap); | |
57 | ||
58 | WXPixmap GetPixmap() const { return m_pixmap; } | |
59 | void SetPixmap(WXPixmap pixmap) { m_pixmap = pixmap; } | |
60 | ||
61 | protected: | |
62 | WXPixmap m_pixmap; | |
63 | }; | |
64 | ||
65 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData | |
66 | { | |
67 | friend class WXDLLEXPORT wxBitmap; | |
68 | friend class WXDLLEXPORT wxIcon; | |
69 | friend class WXDLLEXPORT wxCursor; | |
70 | public: | |
71 | wxBitmapRefData(); | |
72 | ~wxBitmapRefData(); | |
73 | ||
74 | public: | |
75 | int m_width; | |
76 | int m_height; | |
77 | int m_depth; | |
78 | bool m_ok; | |
79 | int m_numColors; | |
80 | wxPalette m_bitmapPalette; | |
81 | int m_quality; | |
82 | ||
83 | wxMask * m_bitmapMask; // Optional mask | |
84 | ||
85 | // Motif implementation | |
86 | public: | |
87 | WXPixmap m_pixmap; | |
88 | WXDisplay* m_display; | |
89 | bool m_freePixmap; | |
90 | unsigned long* m_freeColors; | |
91 | long m_freeColorsCount; | |
83df96d6 JS |
92 | }; |
93 | ||
94 | #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) | |
95 | ||
96 | class WXDLLEXPORT wxBitmapHandler: public wxObject | |
97 | { | |
98 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
99 | public: | |
100 | wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; }; | |
101 | ||
102 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); | |
103 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
104 | int desiredWidth, int desiredHeight); | |
105 | virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); | |
106 | ||
107 | void SetName(const wxString& name) { m_name = name; } | |
108 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
109 | void SetType(long type) { m_type = type; } | |
110 | wxString GetName() const { return m_name; } | |
111 | wxString GetExtension() const { return m_extension; } | |
112 | long GetType() const { return m_type; } | |
113 | protected: | |
114 | wxString m_name; | |
115 | wxString m_extension; | |
116 | long m_type; | |
117 | }; | |
118 | ||
119 | #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) | |
120 | ||
121 | class WXDLLEXPORT wxBitmap: public wxGDIObject | |
122 | { | |
123 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
124 | ||
125 | friend class WXDLLEXPORT wxBitmapHandler; | |
126 | ||
127 | public: | |
128 | wxBitmap(); // Platform-specific | |
129 | ||
130 | // Copy constructors | |
131 | wxBitmap(const wxBitmap& bitmap) | |
132 | { Ref(bitmap); } | |
133 | ||
134 | // Initialize with raw XBM data | |
135 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
136 | ||
137 | // from XPM | |
7266b672 JS |
138 | wxBitmap(const char **data) { (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); } |
139 | wxBitmap(char **data) { (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); } | |
83df96d6 | 140 | |
83df96d6 JS |
141 | // Load a file or resource |
142 | wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_XPM); | |
143 | ||
144 | // Constructor for generalised creation from data | |
145 | wxBitmap(void *data, long type, int width, int height, int depth = 1); | |
146 | ||
147 | // If depth is omitted, will create a bitmap compatible with the display | |
148 | wxBitmap(int width, int height, int depth = -1); | |
149 | ||
150 | // Convert from wxImage: | |
151 | wxBitmap(const wxImage& image, int depth = -1) { (void)CreateFromImage(image, depth); } | |
152 | ||
153 | ~wxBitmap(); | |
154 | ||
155 | virtual bool Create(int width, int height, int depth = -1); | |
156 | virtual bool Create(void *data, long type, int width, int height, int depth = 1); | |
157 | ||
158 | wxBitmap GetSubBitmap( const wxRect& rect ) const; | |
159 | ||
160 | virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_XPM); | |
161 | virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); | |
162 | ||
163 | wxImage ConvertToImage() const; | |
7266b672 JS |
164 | |
165 | bool CopyFromIcon(const wxIcon& icon); | |
83df96d6 JS |
166 | |
167 | bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); } | |
168 | int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } | |
169 | int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } | |
170 | int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } | |
171 | int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } | |
172 | void SetWidth(int w); | |
173 | void SetHeight(int h); | |
174 | void SetDepth(int d); | |
175 | void SetQuality(int q); | |
176 | void SetOk(bool isOk); | |
177 | ||
178 | wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } | |
179 | void SetPalette(const wxPalette& palette); | |
180 | ||
181 | wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); } | |
182 | void SetMask(wxMask *mask) ; | |
183 | ||
184 | wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } | |
185 | bool operator == (const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; } | |
186 | bool operator != (const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; } | |
187 | ||
188 | // Format handling | |
189 | static wxList& GetHandlers() { return sm_handlers; } | |
190 | static void AddHandler(wxBitmapHandler *handler); | |
191 | static void InsertHandler(wxBitmapHandler *handler); | |
192 | static bool RemoveHandler(const wxString& name); | |
193 | static wxBitmapHandler *FindHandler(const wxString& name); | |
194 | static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType); | |
195 | static wxBitmapHandler *FindHandler(long bitmapType); | |
196 | ||
197 | static void InitStandardHandlers(); | |
198 | static void CleanUpHandlers(); | |
199 | ||
200 | // Motif implementation | |
201 | public: | |
202 | WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; } | |
203 | WXPixmap GetPixmap() const { return (WXPixmap) M_BITMAPDATA->m_pixmap; } | |
83df96d6 JS |
204 | void SetPixmapNull() { M_BITMAPDATA->m_pixmap = 0; } |
205 | ||
206 | protected: | |
207 | static wxList sm_handlers; | |
208 | ||
209 | protected: | |
83df96d6 JS |
210 | bool CreateFromImage(const wxImage& image, int depth); |
211 | }; | |
212 | ||
213 | // Creates a bitmap with transparent areas drawn in | |
214 | // the given colour. | |
215 | wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour); | |
216 | ||
217 | #endif | |
218 | // _WX_BITMAP_H_ |