]>
Commit | Line | Data |
---|---|---|
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 | ||
57 | inline WXPixmap GetPixmap() const { return m_pixmap; } | |
58 | ||
59 | protected: | |
60 | WXPixmap m_pixmap; | |
61 | }; | |
62 | ||
63 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData | |
64 | { | |
65 | friend class WXDLLEXPORT wxBitmap; | |
66 | friend class WXDLLEXPORT wxIcon; | |
67 | friend class WXDLLEXPORT wxCursor; | |
68 | public: | |
69 | wxBitmapRefData(); | |
70 | ~wxBitmapRefData(); | |
71 | ||
72 | public: | |
73 | int m_width; | |
74 | int m_height; | |
75 | int m_depth; | |
76 | bool m_ok; | |
77 | int m_numColors; | |
78 | wxPalette m_bitmapPalette; | |
79 | int m_quality; | |
80 | ||
81 | wxMask * m_bitmapMask; // Optional mask | |
82 | ||
83 | // Motif implementation | |
84 | public: | |
85 | WXPixmap m_pixmap; | |
86 | WXDisplay* m_display; | |
87 | }; | |
88 | ||
89 | #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) | |
90 | ||
91 | class WXDLLEXPORT wxBitmapHandler: public wxObject | |
92 | { | |
93 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
94 | public: | |
95 | wxBitmapHandler() { m_name = ""; m_extension = ""; m_type = 0; }; | |
96 | ||
97 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); | |
98 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
99 | int desiredWidth, int desiredHeight); | |
100 | virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); | |
101 | ||
102 | inline void SetName(const wxString& name) { m_name = name; } | |
103 | inline void SetExtension(const wxString& ext) { m_extension = ext; } | |
104 | inline void SetType(long type) { m_type = type; } | |
105 | inline wxString GetName() const { return m_name; } | |
106 | inline wxString GetExtension() const { return m_extension; } | |
107 | inline long GetType() const { return m_type; } | |
108 | protected: | |
109 | wxString m_name; | |
110 | wxString m_extension; | |
111 | long m_type; | |
112 | }; | |
113 | ||
114 | #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) | |
115 | ||
116 | class WXDLLEXPORT wxBitmap: public wxGDIObject | |
117 | { | |
118 | DECLARE_DYNAMIC_CLASS(wxBitmap) | |
119 | ||
120 | friend class WXDLLEXPORT wxBitmapHandler; | |
121 | ||
122 | public: | |
123 | wxBitmap(); // Platform-specific | |
124 | ||
125 | // Copy constructors | |
126 | inline wxBitmap(const wxBitmap& bitmap) | |
127 | { Ref(bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } | |
128 | inline wxBitmap(const wxBitmap* bitmap) { if (bitmap) Ref(*bitmap); if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } | |
129 | ||
130 | // Initialize with raw data. | |
131 | wxBitmap(const char bits[], int width, int height, int depth = 1); | |
132 | ||
133 | /* TODO: maybe implement XPM reading | |
134 | // Initialize with XPM data | |
135 | wxBitmap(const char **data); | |
136 | */ | |
137 | ||
138 | // Load a file or resource | |
139 | // TODO: make default type whatever's appropriate for the platform. | |
140 | wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); | |
141 | ||
142 | // Constructor for generalised creation from data | |
143 | wxBitmap(void *data, long type, int width, int height, int depth = 1); | |
144 | ||
145 | // If depth is omitted, will create a bitmap compatible with the display | |
146 | wxBitmap(int width, int height, int depth = -1); | |
147 | ~wxBitmap(); | |
148 | ||
149 | virtual bool Create(int width, int height, int depth = -1); | |
150 | virtual bool Create(void *data, long type, int width, int height, int depth = 1); | |
151 | virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); | |
152 | virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); | |
153 | ||
154 | inline bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); } | |
155 | inline int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } | |
156 | inline int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } | |
157 | inline int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } | |
158 | inline int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } | |
159 | void SetWidth(int w); | |
160 | void SetHeight(int h); | |
161 | void SetDepth(int d); | |
162 | void SetQuality(int q); | |
163 | void SetOk(bool isOk); | |
164 | ||
165 | inline wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } | |
166 | void SetPalette(const wxPalette& palette); | |
167 | ||
168 | inline wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); } | |
169 | void SetMask(wxMask *mask) ; | |
170 | ||
171 | inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } | |
172 | inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; } | |
173 | inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; } | |
174 | ||
175 | // Format handling | |
176 | static inline wxList& GetHandlers() { return sm_handlers; } | |
177 | static void AddHandler(wxBitmapHandler *handler); | |
178 | static void InsertHandler(wxBitmapHandler *handler); | |
179 | static bool RemoveHandler(const wxString& name); | |
180 | static wxBitmapHandler *FindHandler(const wxString& name); | |
181 | static wxBitmapHandler *FindHandler(const wxString& extension, long bitmapType); | |
182 | static wxBitmapHandler *FindHandler(long bitmapType); | |
183 | ||
184 | static void InitStandardHandlers(); | |
185 | static void CleanUpHandlers(); | |
186 | ||
187 | // Motif implementation | |
188 | public: | |
189 | inline WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; } | |
190 | inline WXDisplay* GetPixmap() const { return M_BITMAPDATA->m_pixmap; } | |
191 | ||
192 | protected: | |
193 | static wxList sm_handlers; | |
194 | ||
195 | ||
196 | }; | |
197 | #endif | |
198 | // _WX_BITMAP_H_ |