]>
Commit | Line | Data |
---|---|---|
9b6dbb09 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 | ||
31 | // A mask is a mono bitmap used for drawing bitmaps | |
32 | // transparently. | |
33 | class WXDLLEXPORT wxMask: public wxObject | |
34 | { | |
35 | DECLARE_DYNAMIC_CLASS(wxMask) | |
36 | ||
37 | public: | |
38 | wxMask(); | |
39 | ||
40 | // Construct a mask from a bitmap and a colour indicating | |
41 | // the transparent area | |
42 | wxMask(const wxBitmap& bitmap, const wxColour& colour); | |
43 | ||
44 | // Construct a mask from a bitmap and a palette index indicating | |
45 | // the transparent area | |
46 | wxMask(const wxBitmap& bitmap, int paletteIndex); | |
47 | ||
48 | // Construct a mask from a mono bitmap (copies the bitmap). | |
49 | wxMask(const wxBitmap& bitmap); | |
50 | ||
51 | ~wxMask(); | |
52 | ||
53 | bool Create(const wxBitmap& bitmap, const wxColour& colour); | |
54 | bool Create(const wxBitmap& bitmap, int paletteIndex); | |
55 | bool Create(const wxBitmap& bitmap); | |
56 | ||
72cdf4c9 VZ |
57 | WXPixmap GetPixmap() const { return m_pixmap; } |
58 | void SetPixmap(WXPixmap pixmap) { m_pixmap = pixmap; } | |
16c1f7f3 | 59 | |
9b6dbb09 | 60 | protected: |
16c1f7f3 | 61 | WXPixmap m_pixmap; |
9b6dbb09 JS |
62 | }; |
63 | ||
64 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData | |
65 | { | |
66 | friend class WXDLLEXPORT wxBitmap; | |
67 | friend class WXDLLEXPORT wxIcon; | |
68 | friend class WXDLLEXPORT wxCursor; | |
69 | public: | |
70 | wxBitmapRefData(); | |
71 | ~wxBitmapRefData(); | |
72 | ||
73 | public: | |
f97c9854 JS |
74 | int m_width; |
75 | int m_height; | |
76 | int m_depth; | |
77 | bool m_ok; | |
78 | int m_numColors; | |
79 | wxPalette m_bitmapPalette; | |
80 | int m_quality; | |
9b6dbb09 | 81 | |
f97c9854 | 82 | wxMask * m_bitmapMask; // Optional mask |
16c1f7f3 JS |
83 | |
84 | // Motif implementation | |
85 | public: | |
f97c9854 JS |
86 | WXPixmap m_pixmap; |
87 | WXDisplay* m_display; | |
88 | bool m_freePixmap; | |
89 | unsigned long* m_freeColors; | |
90 | long m_freeColorsCount; | |
91 | ||
92 | // These 5 variables are for wxControl | |
93 | WXPixmap m_insensPixmap ; | |
94 | WXPixmap m_labelPixmap ; | |
95 | WXPixmap m_armPixmap ; | |
96 | WXImage* m_image ; | |
97 | WXImage* m_insensImage ; | |
9b6dbb09 JS |
98 | }; |
99 | ||
100 | #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) | |
101 | ||
102 | class WXDLLEXPORT wxBitmapHandler: public wxObject | |
103 | { | |
104 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
105 | public: | |
106 | wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; }; | |
107 | ||
108 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); | |
109 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
110 | int desiredWidth, int desiredHeight); | |
111 | virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); | |
112 | ||
72cdf4c9 VZ |
113 | void SetName(const wxString& name) { m_name = name; } |
114 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
115 | void SetType(long type) { m_type = type; } | |
116 | wxString GetName() const { return m_name; } | |
117 | wxString GetExtension() const { return m_extension; } | |
118 | long GetType() const { return m_type; } | |
9b6dbb09 JS |
119 | protected: |
120 | wxString m_name; | |
121 | wxString m_extension; | |
122 | long m_type; | |
123 | }; | |
124 | ||
125 | #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) | |
126 | ||
127 | class WXDLLEXPORT wxBitmap: public wxGDIObject | |
128 | { | |
129 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
130 | ||
131 | friend class WXDLLEXPORT wxBitmapHandler; | |
132 | ||
133 | public: | |
134 | wxBitmap(); // Platform-specific | |
135 | ||
136 | // Copy constructors | |
72cdf4c9 | 137 | wxBitmap(const wxBitmap& bitmap) |
9b6dbb09 | 138 | { Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } |
9b6dbb09 | 139 | |
f97c9854 | 140 | // Initialize with raw XBM data |
9b6dbb09 JS |
141 | wxBitmap(const char bits[], int width, int height, int depth = 1); |
142 | ||
e838cc14 VZ |
143 | // from XPM |
144 | wxBitmap(const char **data) { (void)CreateFromXpm(data); } | |
145 | wxBitmap(char **data) { (void)CreateFromXpm((const char **)data); } | |
146 | ||
147 | // Initialize with XPM data -- deprecated | |
148 | wxBitmap(char **data, wxControl* control); | |
9b6dbb09 JS |
149 | |
150 | // Load a file or resource | |
cba2db0c | 151 | wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_XPM); |
9b6dbb09 JS |
152 | |
153 | // Constructor for generalised creation from data | |
154 | wxBitmap(void *data, long type, int width, int height, int depth = 1); | |
155 | ||
156 | // If depth is omitted, will create a bitmap compatible with the display | |
157 | wxBitmap(int width, int height, int depth = -1); | |
158 | ~wxBitmap(); | |
159 | ||
160 | virtual bool Create(int width, int height, int depth = -1); | |
161 | virtual bool Create(void *data, long type, int width, int height, int depth = 1); | |
cba2db0c | 162 | virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_XPM); |
9b6dbb09 JS |
163 | virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); |
164 | ||
72cdf4c9 VZ |
165 | bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); } |
166 | int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } | |
167 | int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } | |
168 | int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } | |
169 | int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } | |
9b6dbb09 JS |
170 | void SetWidth(int w); |
171 | void SetHeight(int h); | |
172 | void SetDepth(int d); | |
173 | void SetQuality(int q); | |
174 | void SetOk(bool isOk); | |
175 | ||
72cdf4c9 | 176 | wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } |
9b6dbb09 JS |
177 | void SetPalette(const wxPalette& palette); |
178 | ||
72cdf4c9 | 179 | wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); } |
9b6dbb09 JS |
180 | void SetMask(wxMask *mask) ; |
181 | ||
72cdf4c9 VZ |
182 | wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } |
183 | bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; } | |
184 | bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; } | |
9b6dbb09 JS |
185 | |
186 | // Format handling | |
72cdf4c9 | 187 | static wxList& GetHandlers() { return sm_handlers; } |
9b6dbb09 JS |
188 | static void AddHandler(wxBitmapHandler *handler); |
189 | static void InsertHandler(wxBitmapHandler *handler); | |
190 | static bool RemoveHandler(const wxString& name); | |
191 | static wxBitmapHandler *FindHandler(const wxString& name); | |
192 | static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType); | |
193 | static wxBitmapHandler *FindHandler(long bitmapType); | |
194 | ||
195 | static void InitStandardHandlers(); | |
196 | static void CleanUpHandlers(); | |
16c1f7f3 JS |
197 | |
198 | // Motif implementation | |
199 | public: | |
72cdf4c9 VZ |
200 | WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; } |
201 | WXDisplay* GetPixmap() const { return M_BITMAPDATA->m_pixmap; } | |
f97c9854 JS |
202 | virtual WXPixmap GetLabelPixmap(WXWidget w) ; |
203 | virtual WXPixmap GetArmPixmap(WXWidget w) ; | |
0d57be45 | 204 | virtual WXPixmap GetInsensPixmap(WXWidget w = (WXWidget) 0) ; |
16c1f7f3 | 205 | |
9b6dbb09 JS |
206 | protected: |
207 | static wxList sm_handlers; | |
e838cc14 VZ |
208 | |
209 | protected: | |
210 | bool CreateFromXpm(const char **bits); | |
9b6dbb09 | 211 | }; |
321db4b6 JS |
212 | |
213 | // Creates a bitmap with transparent areas drawn in | |
214 | // the given colour. | |
d166a4f8 | 215 | wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour); |
321db4b6 | 216 | |
9b6dbb09 JS |
217 | #endif |
218 | // _WX_BITMAP_H_ |