]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
wxNativeFontInfo changes
[wxWidgets.git] / include / wx / os2 / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
5 // Modified by:
6 // Created: 11/28/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
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/os2/private.h"
20 #include "wx/os2/gdiimage.h"
21 #include "wx/gdicmn.h"
22 #include "wx/palette.h"
23
24 class WXDLLEXPORT wxDC;
25 class WXDLLEXPORT wxControl;
26 class WXDLLEXPORT wxBitmap;
27 class WXDLLEXPORT wxBitmapHandler;
28 class WXDLLEXPORT wxIcon;
29 class WXDLLEXPORT wxMask;
30 class WXDLLEXPORT wxCursor;
31 class WXDLLEXPORT wxControl;
32
33 // ----------------------------------------------------------------------------
34 // Bitmap data
35 //
36 // NB: this class is private, but declared here to make it possible inline
37 // wxBitmap functions accessing it
38 // ----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
41 {
42 public:
43 wxBitmapRefData();
44 virtual ~wxBitmapRefData() { Free(); }
45
46 virtual void Free();
47
48 public:
49 int m_nNumColors;
50 wxPalette m_vBitmapPalette;
51 int m_nQuality;
52
53 // OS2-specific
54 // ------------
55
56 wxDC* m_pSelectedInto;
57 HPS m_hPresentationSpace;
58 LONG m_lId;
59
60 // optional mask for transparent drawing
61 wxMask* m_pBitmapMask;
62 };
63
64 // ----------------------------------------------------------------------------
65 // wxBitmap: a mono or colour bitmap
66 // ----------------------------------------------------------------------------
67
68 class WXDLLEXPORT wxBitmap : public wxGDIImage
69 {
70 public:
71 // default ctor creates an invalid bitmap, you must Create() it later
72 wxBitmap() { Init(); }
73
74 // Copy constructors
75 inline wxBitmap(const wxBitmap& rBitmap)
76 { Init(); Ref(rBitmap); }
77
78 // Initialize with raw data
79 wxBitmap( const char bits[]
80 ,int nWidth
81 ,int nHeight
82 ,int nDepth = 1
83 );
84
85 // Initialize with XPM data
86 wxBitmap( char** ppData
87 ,wxControl* pAnItem = NULL
88 );
89
90 // Load a file or resource
91 wxBitmap( const wxString& rName
92 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
93 );
94
95 // New constructor for generalised creation from data
96 wxBitmap( void* pData
97 ,long lType
98 ,int nWidth
99 ,int nHeight
100 ,int nDepth = 1
101 );
102
103 // If depth is omitted, will create a bitmap compatible with the display
104 wxBitmap( int nWidth
105 ,int nHeight
106 ,int nDepth = -1
107 );
108
109 // we must have this, otherwise icons are silently copied into bitmaps using
110 // the copy ctor but the resulting bitmap is invalid!
111 inline wxBitmap(const wxIcon& rIcon)
112 { Init(); CopyFromIcon(rIcon); }
113
114 wxBitmap& operator=(const wxBitmap& rBitmap)
115 {
116 if ( m_refData != rBitmap.m_refData )
117 Ref(rBitmap);
118 return(*this);
119 }
120
121 wxBitmap& operator=(const wxIcon& rIcon)
122 {
123 (void)CopyFromIcon(rIcon);
124
125 return(*this);
126 }
127
128 wxBitmap& operator=(const wxCursor& rCursor)
129 {
130 (void)CopyFromCursor(rCursor);
131 return (*this);
132 }
133
134 virtual ~wxBitmap();
135
136 // copies the contents and mask of the given (colour) icon to the bitmap
137 bool CopyFromIcon(const wxIcon& rIcon);
138
139 // copies the contents and mask of the given cursor to the bitmap
140 bool CopyFromCursor(const wxCursor& rCursor);
141
142 virtual bool Create( int nWidth
143 ,int nHeight
144 ,int nDepth = -1
145 );
146 virtual bool Create( void* pData
147 ,long lType
148 ,int nWidth
149 ,int nHeight
150 ,int nDepth = 1
151 );
152 virtual bool LoadFile( const wxString& rName
153 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
154 );
155 virtual bool SaveFile( const wxString& rName
156 ,int lType
157 ,const wxPalette* pCmap = NULL
158 );
159
160 inline wxBitmapRefData* GetBitmapData() const
161 { return (wxBitmapRefData *)m_refData; }
162
163 inline int GetQuality() const
164 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
165
166 void SetQuality(int nQ);
167
168 wxPalette* GetPalette() const
169 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
170
171 void SetPalette(const wxPalette& rPalette);
172
173 inline wxMask* GetMask() const
174 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
175
176 void SetMask(wxMask* pMask) ;
177
178 inline bool operator==(const wxBitmap& rBitmap)
179 { return m_refData == rBitmap.m_refData; }
180
181 inline bool operator!=(const wxBitmap& rBitmap)
182 { return m_refData != rBitmap.m_refData; }
183
184 #if WXWIN_COMPATIBILITY_2
185 void SetOk(bool bIsOk);
186 #endif // WXWIN_COMPATIBILITY_2
187
188 #if WXWIN_COMPATIBILITY
189 inline wxPalette* GetColourMap() const
190 { return GetPalette(); }
191
192 inline void SetColourMap(wxPalette* pCmap)
193 { SetPalette(*pCmap); };
194
195 #endif // WXWIN_COMPATIBILITY
196
197 // Implementation
198 public:
199 inline void SetHBITMAP(WXHBITMAP hBmp)
200 { SetHandle((WXHANDLE)hBmp); }
201
202 inline WXHBITMAP GetHBITMAP() const
203 { return (WXHBITMAP)GetHandle(); }
204
205 inline void SetSelectedInto(wxDC* pDc)
206 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
207
208 inline wxDC* GetSelectedInto() const
209 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
210
211 // An OS/2 version that probably doesn't do anything like the msw version
212 wxBitmap GetBitmapForDC(wxDC& rDc) const;
213
214 inline LONG GetId() const
215 { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); }
216
217
218 protected:
219 // common part of all ctors
220 void Init();
221
222 inline virtual wxGDIImageRefData* CreateData() const
223 { return new wxBitmapRefData; }
224
225 private:
226 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
227
228 DECLARE_DYNAMIC_CLASS(wxBitmap)
229 };
230
231 // ----------------------------------------------------------------------------
232 // wxMask: a mono bitmap used for drawing bitmaps transparently.
233 // ----------------------------------------------------------------------------
234
235 class WXDLLEXPORT wxMask : public wxObject
236 {
237 public:
238 wxMask();
239
240 // Construct a mask from a bitmap and a colour indicating the transparent
241 // area
242 wxMask( const wxBitmap& rBitmap
243 ,const wxColour& rColour
244 );
245
246 // Construct a mask from a bitmap and a palette index indicating the
247 // transparent area
248 wxMask( const wxBitmap& rBitmap
249 ,int nPaletteIndex
250 );
251
252 // Construct a mask from a mono bitmap (copies the bitmap).
253 wxMask(const wxBitmap& rBitmap);
254
255 // construct a mask from the givne bitmap handle
256 wxMask(WXHBITMAP hBmp)
257 { m_hMaskBitmap = hBmp; }
258
259 virtual ~wxMask();
260
261 bool Create( const wxBitmap& bitmap
262 ,const wxColour& rColour
263 );
264 bool Create( const wxBitmap& rBitmap
265 ,int nPaletteIndex
266 );
267 bool Create(const wxBitmap& rBitmap);
268
269 // Implementation
270 WXHBITMAP GetMaskBitmap() const
271 { return m_hMaskBitmap; }
272 void SetMaskBitmap(WXHBITMAP hBmp)
273 { m_hMaskBitmap = hBmp; }
274
275 protected:
276 WXHBITMAP m_hMaskBitmap;
277 DECLARE_DYNAMIC_CLASS(wxMask)
278 private:
279 HDC m_hDc;
280 HPS m_hPs;
281 };
282
283 // ----------------------------------------------------------------------------
284 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
285 // ----------------------------------------------------------------------------
286
287 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
288 {
289 public:
290 inline wxBitmapHandler()
291 { m_lType = wxBITMAP_TYPE_INVALID; }
292
293 inline wxBitmapHandler( const wxString& rName
294 ,const wxString& rExt
295 ,long lType
296 )
297 : wxGDIImageHandler( rName
298 ,rExt
299 ,lType)
300 {
301 }
302
303 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
304 // old class which worked only with bitmaps
305 virtual bool Create( wxBitmap* pBitmap
306 ,void* pData
307 ,long lFlags
308 ,int nWidth
309 ,int nHeight
310 ,int nDepth = 1
311 );
312 virtual bool LoadFile( wxBitmap* pBitmap
313 ,const wxString& rName
314 ,HPS hPs
315 ,long lFlags
316 ,int nDesiredWidth
317 ,int nDesiredHeight
318 );
319 virtual bool SaveFile( wxBitmap* pBitmap
320 ,const wxString& rName
321 ,int lType
322 ,const wxPalette* pPalette = NULL
323 );
324
325 virtual bool Create( wxGDIImage* pImage
326 ,void* pData
327 ,long lFlags
328 ,int nWidth
329 ,int nHeight
330 ,int nDepth = 1
331 );
332 virtual bool Load( wxGDIImage* pImage
333 ,const wxString& rName
334 ,HPS hPs
335 ,long lFlags
336 ,int nDesiredWidth
337 ,int nDesiredHeight
338 );
339 virtual bool Save( wxGDIImage* pImage
340 ,const wxString& rName
341 ,int lType
342 );
343 private:
344 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
345 };
346
347 #endif
348 // _WX_BITMAP_H_