]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
More of the same.
[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); }
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 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 wxBitmap( const wxImage& image, int depth = -1 )
110 { (void)CreateFromImage(image, depth); }
111
112 // we must have this, otherwise icons are silently copied into bitmaps using
113 // the copy ctor but the resulting bitmap is invalid!
114 inline wxBitmap(const wxIcon& rIcon)
115 { Init(); CopyFromIcon(rIcon); }
116
117 wxBitmap& operator=(const wxBitmap& rBitmap)
118 {
119 if ( m_refData != rBitmap.m_refData )
120 Ref(rBitmap);
121 return(*this);
122 }
123
124 wxBitmap& operator=(const wxIcon& rIcon)
125 {
126 (void)CopyFromIcon(rIcon);
127
128 return(*this);
129 }
130
131 wxBitmap& operator=(const wxCursor& rCursor)
132 {
133 (void)CopyFromCursor(rCursor);
134 return (*this);
135 }
136
137 virtual ~wxBitmap();
138
139 wxImage ConvertToImage() const;
140
141 // get the given part of bitmap
142 wxBitmap GetSubBitmap(const wxRect& rRect) const;
143
144 // copies the contents and mask of the given (colour) icon to the bitmap
145 bool CopyFromIcon(const wxIcon& rIcon);
146
147 // copies the contents and mask of the given cursor to the bitmap
148 bool CopyFromCursor(const wxCursor& rCursor);
149
150 virtual bool Create( int nWidth
151 ,int nHeight
152 ,int nDepth = -1
153 );
154 virtual bool Create( void* pData
155 ,long lType
156 ,int nWidth
157 ,int nHeight
158 ,int nDepth = 1
159 );
160 virtual bool LoadFile( const wxString& rName
161 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
162 );
163 virtual bool SaveFile( const wxString& rName
164 ,int lType
165 ,const wxPalette* pCmap = NULL
166 );
167
168 inline wxBitmapRefData* GetBitmapData() const
169 { return (wxBitmapRefData *)m_refData; }
170
171 inline int GetQuality() const
172 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
173
174 void SetQuality(int nQ);
175
176 wxPalette* GetPalette() const
177 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
178
179 void SetPalette(const wxPalette& rPalette);
180
181 inline wxMask* GetMask() const
182 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
183
184 void SetMask(wxMask* pMask) ;
185
186 inline bool operator==(const wxBitmap& rBitmap) const
187 { return m_refData == rBitmap.m_refData; }
188
189 inline bool operator!=(const wxBitmap& rBitmap) const
190 { return m_refData != rBitmap.m_refData; }
191
192 #if WXWIN_COMPATIBILITY_2
193 void SetOk(bool bIsOk);
194 #endif // WXWIN_COMPATIBILITY_2
195
196 #if WXWIN_COMPATIBILITY
197 inline wxPalette* GetColourMap() const
198 { return GetPalette(); }
199
200 inline void SetColourMap(wxPalette* pCmap)
201 { SetPalette(*pCmap); };
202
203 #endif // WXWIN_COMPATIBILITY
204
205 // Implementation
206 public:
207 inline void SetHBITMAP(WXHBITMAP hBmp)
208 { SetHandle((WXHANDLE)hBmp); }
209
210 inline WXHBITMAP GetHBITMAP() const
211 { return (WXHBITMAP)GetHandle(); }
212
213 inline void SetSelectedInto(wxDC* pDc)
214 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
215
216 inline wxDC* GetSelectedInto() const
217 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
218
219 inline bool IsMono(void) const { return m_bIsMono; }
220 inline bool Flip(void) const { return m_bFlip; }
221
222
223 // An OS/2 version that probably doesn't do anything like the msw version
224 wxBitmap GetBitmapForDC(wxDC& rDc) const;
225
226 // inline LONG GetId() const
227 // { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); }
228
229
230 protected:
231 // common part of all ctors
232 void Init();
233
234 inline virtual wxGDIImageRefData* CreateData() const
235 { return new wxBitmapRefData; }
236
237 // creates the bitmap from XPM data, supposed to be called from ctor
238 bool CreateFromXpm(const char** ppData);
239 bool CreateFromImage(const wxImage& image, int depth);
240
241 private:
242 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
243
244 bool m_bIsMono;
245 bool m_bFlip;
246 DECLARE_DYNAMIC_CLASS(wxBitmap)
247 }; // end of CLASS wxBitmap
248
249 // ----------------------------------------------------------------------------
250 // wxMask: a mono bitmap used for drawing bitmaps transparently.
251 // ----------------------------------------------------------------------------
252
253 class WXDLLEXPORT wxMask : public wxObject
254 {
255 public:
256 wxMask();
257
258 // Construct a mask from a bitmap and a colour indicating the transparent
259 // area
260 wxMask( const wxBitmap& rBitmap
261 ,const wxColour& rColour
262 );
263
264 // Construct a mask from a bitmap and a palette index indicating the
265 // transparent area
266 wxMask( const wxBitmap& rBitmap
267 ,int nPaletteIndex
268 );
269
270 // Construct a mask from a mono bitmap (copies the bitmap).
271 wxMask(const wxBitmap& rBitmap);
272
273 // construct a mask from the givne bitmap handle
274 wxMask(WXHBITMAP hBmp)
275 { m_hMaskBitmap = hBmp; }
276
277 virtual ~wxMask();
278
279 bool Create( const wxBitmap& bitmap
280 ,const wxColour& rColour
281 );
282 bool Create( const wxBitmap& rBitmap
283 ,int nPaletteIndex
284 );
285 bool Create(const wxBitmap& rBitmap);
286
287 // Implementation
288 WXHBITMAP GetMaskBitmap() const
289 { return m_hMaskBitmap; }
290 void SetMaskBitmap(WXHBITMAP hBmp)
291 { m_hMaskBitmap = hBmp; }
292
293 protected:
294 WXHBITMAP m_hMaskBitmap;
295 DECLARE_DYNAMIC_CLASS(wxMask)
296 }; // end of CLASS wxMask
297
298 // ----------------------------------------------------------------------------
299 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
300 // ----------------------------------------------------------------------------
301
302 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
303 {
304 public:
305 inline wxBitmapHandler()
306 { m_lType = wxBITMAP_TYPE_INVALID; }
307
308 inline wxBitmapHandler( const wxString& rName
309 ,const wxString& rExt
310 ,long lType
311 )
312 : wxGDIImageHandler( rName
313 ,rExt
314 ,lType)
315 {
316 }
317
318 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
319 // old class which worked only with bitmaps
320 virtual bool Create( wxBitmap* pBitmap
321 ,void* pData
322 ,long lFlags
323 ,int nWidth
324 ,int nHeight
325 ,int nDepth = 1
326 );
327 virtual bool LoadFile( wxBitmap* pBitmap
328 ,const wxString& rName
329 ,HPS hPs
330 ,long lFlags
331 ,int nDesiredWidth
332 ,int nDesiredHeight
333 );
334 virtual bool SaveFile( wxBitmap* pBitmap
335 ,const wxString& rName
336 ,int lType
337 ,const wxPalette* pPalette = NULL
338 );
339
340 virtual bool Create( wxGDIImage* pImage
341 ,void* pData
342 ,long lFlags
343 ,int nWidth
344 ,int nHeight
345 ,int nDepth = 1
346 );
347 virtual bool Load( wxGDIImage* pImage
348 ,const wxString& rName
349 ,HPS hPs
350 ,long lFlags
351 ,int nDesiredWidth
352 ,int nDesiredHeight
353 );
354 virtual bool Save( wxGDIImage* pImage
355 ,const wxString& rName
356 ,int lType
357 );
358 private:
359 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
360 }; // end of CLASS wxBitmapHandler
361
362 #endif
363 // _WX_BITMAP_H_