]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
5b5e917b4d8991dd8adf4a8da0ed0c5c2b5914be
[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 class WXDLLEXPORT wxImage;
33
34 // ----------------------------------------------------------------------------
35 // Bitmap data
36 //
37 // NB: this class is private, but declared here to make it possible inline
38 // wxBitmap functions accessing it
39 // ----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
42 {
43 public:
44 wxBitmapRefData();
45 virtual ~wxBitmapRefData() { Free(); }
46
47 virtual void Free();
48
49 public:
50 int m_nNumColors;
51 wxPalette m_vBitmapPalette;
52 int m_nQuality;
53
54 // OS2-specific
55 // ------------
56
57 wxDC* m_pSelectedInto;
58
59 //
60 // Optional mask for transparent drawing
61 //
62 wxMask* m_pBitmapMask;
63 }; // end of CLASS wxBitmapRefData
64
65 // ----------------------------------------------------------------------------
66 // wxBitmap: a mono or colour bitmap
67 // ----------------------------------------------------------------------------
68
69 class WXDLLEXPORT wxBitmap : public wxGDIImage
70 {
71 public:
72 // default ctor creates an invalid bitmap, you must Create() it later
73 wxBitmap() { Init(); }
74
75 // Copy constructors
76 inline wxBitmap(const wxBitmap& rBitmap)
77 { Init(); Ref(rBitmap); SetHandle(rBitmap.GetHandle()); }
78
79 // Initialize with raw data
80 wxBitmap( const char bits[]
81 ,int nWidth
82 ,int nHeight
83 ,int nDepth = 1
84 );
85
86 // Initialize with XPM data
87 wxBitmap(const char** ppData) { CreateFromXpm(ppData); }
88 wxBitmap(char** ppData) { CreateFromXpm((const char**)ppData); }
89
90 // Load a resource
91 wxBitmap( int nId
92 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
93 );
94
95 // For compatiability with other ports, under OS/2 does same as default ctor
96 inline wxBitmap( const wxString& WXUNUSED(rFilename)
97 ,long WXUNUSED(lType)
98 )
99 { Init(); }
100 // New constructor for generalised creation from data
101 wxBitmap( void* pData
102 ,long lType
103 ,int nWidth
104 ,int nHeight
105 ,int nDepth = 1
106 );
107
108 // If depth is omitted, will create a bitmap compatible with the display
109 wxBitmap( int nWidth, int nHeight, int nDepth = -1 );
110
111 wxBitmap( const wxImage& image, int depth = -1 )
112 { (void)CreateFromImage(image, depth); }
113
114 // we must have this, otherwise icons are silently copied into bitmaps using
115 // the copy ctor but the resulting bitmap is invalid!
116 inline wxBitmap(const wxIcon& rIcon)
117 { Init(); CopyFromIcon(rIcon); }
118
119 wxBitmap& operator=(const wxBitmap& rBitmap)
120 {
121 if ( m_refData != rBitmap.m_refData )
122 Ref(rBitmap);
123 return(*this);
124 }
125
126 wxBitmap& operator=(const wxIcon& rIcon)
127 {
128 (void)CopyFromIcon(rIcon);
129
130 return(*this);
131 }
132
133 wxBitmap& operator=(const wxCursor& rCursor)
134 {
135 (void)CopyFromCursor(rCursor);
136 return (*this);
137 }
138
139 virtual ~wxBitmap();
140
141 wxImage ConvertToImage() const;
142
143 // get the given part of bitmap
144 wxBitmap GetSubBitmap(const wxRect& rRect) const;
145
146 // copies the contents and mask of the given (colour) icon to the bitmap
147 bool CopyFromIcon(const wxIcon& rIcon);
148
149 // copies the contents and mask of the given cursor to the bitmap
150 bool CopyFromCursor(const wxCursor& rCursor);
151
152 virtual bool Create( int nWidth
153 ,int nHeight
154 ,int nDepth = -1
155 );
156 virtual bool Create( void* pData
157 ,long lType
158 ,int nWidth
159 ,int nHeight
160 ,int nDepth = 1
161 );
162 virtual bool LoadFile( int nId
163 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
164 );
165 virtual bool LoadFile( const wxString& rName
166 ,long lType = wxBITMAP_TYPE_XPM
167 );
168 virtual bool SaveFile( const wxString& rName
169 ,int lType
170 ,const wxPalette* pCmap = NULL
171 );
172
173 inline wxBitmapRefData* GetBitmapData() const
174 { return (wxBitmapRefData *)m_refData; }
175
176 inline int GetQuality() const
177 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
178
179 void SetQuality(int nQ);
180
181 wxPalette* GetPalette() const
182 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
183
184 void SetPalette(const wxPalette& rPalette);
185
186 inline wxMask* GetMask() const
187 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
188
189 void SetMask(wxMask* pMask) ;
190
191 inline bool operator==(const wxBitmap& rBitmap) const
192 { return m_refData == rBitmap.m_refData; }
193
194 inline bool operator!=(const wxBitmap& rBitmap) const
195 { return m_refData != rBitmap.m_refData; }
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 inline bool IsMono(void) const { return m_bIsMono; }
212
213 // An OS/2 version that probably doesn't do anything like the msw version
214 wxBitmap GetBitmapForDC(wxDC& rDc) const;
215
216 protected:
217 // common part of all ctors
218 void Init();
219
220 inline virtual wxGDIImageRefData* CreateData() const
221 { return new wxBitmapRefData; }
222
223 // creates the bitmap from XPM data, supposed to be called from ctor
224 bool CreateFromXpm(const char** ppData);
225 bool CreateFromImage(const wxImage& image, int depth);
226
227 private:
228 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
229
230 bool m_bIsMono;
231 DECLARE_DYNAMIC_CLASS(wxBitmap)
232 }; // end of CLASS wxBitmap
233
234 // ----------------------------------------------------------------------------
235 // wxMask: a mono bitmap used for drawing bitmaps transparently.
236 // ----------------------------------------------------------------------------
237
238 class WXDLLEXPORT wxMask : public wxObject
239 {
240 public:
241 wxMask();
242
243 // Construct a mask from a bitmap and a colour indicating the transparent
244 // area
245 wxMask( const wxBitmap& rBitmap
246 ,const wxColour& rColour
247 );
248
249 // Construct a mask from a bitmap and a palette index indicating the
250 // transparent area
251 wxMask( const wxBitmap& rBitmap
252 ,int nPaletteIndex
253 );
254
255 // Construct a mask from a mono bitmap (copies the bitmap).
256 wxMask(const wxBitmap& rBitmap);
257
258 // construct a mask from the givne bitmap handle
259 wxMask(WXHBITMAP hBmp)
260 { m_hMaskBitmap = hBmp; }
261
262 virtual ~wxMask();
263
264 bool Create( const wxBitmap& bitmap
265 ,const wxColour& rColour
266 );
267 bool Create( const wxBitmap& rBitmap
268 ,int nPaletteIndex
269 );
270 bool Create(const wxBitmap& rBitmap);
271
272 // Implementation
273 WXHBITMAP GetMaskBitmap() const
274 { return m_hMaskBitmap; }
275 void SetMaskBitmap(WXHBITMAP hBmp)
276 { m_hMaskBitmap = hBmp; }
277
278 protected:
279 WXHBITMAP m_hMaskBitmap;
280 DECLARE_DYNAMIC_CLASS(wxMask)
281 }; // end of CLASS wxMask
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 ,int nId
314 ,long lFlags
315 ,int nDesiredWidth
316 ,int nDesiredHeight
317 );
318 virtual bool LoadFile( wxBitmap* pBitmap
319 ,const wxString& rName
320 ,long lFlags
321 ,int nDesiredWidth
322 ,int nDesiredHeight
323 );
324 virtual bool SaveFile( wxBitmap* pBitmap
325 ,const wxString& rName
326 ,int lType
327 ,const wxPalette* pPalette = NULL
328 );
329
330 virtual bool Create( wxGDIImage* pImage
331 ,void* pData
332 ,long lFlags
333 ,int nWidth
334 ,int nHeight
335 ,int nDepth = 1
336 );
337 virtual bool Load( wxGDIImage* pImage
338 ,int nId
339 ,long lFlags
340 ,int nDesiredWidth
341 ,int nDesiredHeight
342 );
343 virtual bool Save( wxGDIImage* pImage
344 ,const wxString& rName
345 ,int lType
346 );
347 private:
348 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
349 ,const wxString& WXUNUSED(rName)
350 ,HPS WXUNUSED(hPs)
351 ,long WXUNUSED(lFlags)
352 ,int WXUNUSED(nDesiredWidth)
353 ,int WXUNUSED(nDesiredHeight)
354 )
355 { return false; }
356 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
357 }; // end of CLASS wxBitmapHandler
358
359 #endif
360 // _WX_BITMAP_H_