]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
Minor header cleaning.
[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 #include "wx/os2/private.h"
16 #include "wx/os2/gdiimage.h"
17 #include "wx/gdicmn.h"
18 #include "wx/palette.h"
19
20 class WXDLLEXPORT wxDC;
21 class WXDLLEXPORT wxControl;
22 class WXDLLEXPORT wxBitmap;
23 class WXDLLEXPORT wxBitmapHandler;
24 class WXDLLEXPORT wxIcon;
25 class WXDLLEXPORT wxMask;
26 class WXDLLEXPORT wxCursor;
27 class WXDLLEXPORT wxControl;
28 class WXDLLEXPORT wxImage;
29
30 // ----------------------------------------------------------------------------
31 // Bitmap data
32 //
33 // NB: this class is private, but declared here to make it possible inline
34 // wxBitmap functions accessing it
35 // ----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
38 {
39 public:
40 wxBitmapRefData();
41 virtual ~wxBitmapRefData() { Free(); }
42
43 virtual void Free();
44
45 public:
46 int m_nNumColors;
47 wxPalette m_vBitmapPalette;
48 int m_nQuality;
49
50 // OS2-specific
51 // ------------
52
53 wxDC* m_pSelectedInto;
54
55 //
56 // Optional mask for transparent drawing
57 //
58 wxMask* m_pBitmapMask;
59 }; // end of CLASS wxBitmapRefData
60
61 // ----------------------------------------------------------------------------
62 // wxBitmap: a mono or colour bitmap
63 // ----------------------------------------------------------------------------
64
65 class WXDLLEXPORT wxBitmap : public wxGDIImage
66 {
67 public:
68 // default ctor creates an invalid bitmap, you must Create() it later
69 wxBitmap() { Init(); }
70
71 // Copy constructors
72 inline wxBitmap(const wxBitmap& rBitmap)
73 : wxGDIImage(rBitmap)
74 {
75 Init();
76 SetHandle(rBitmap.GetHandle());
77 }
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 wxIcon& rIcon)
120 {
121 (void)CopyFromIcon(rIcon);
122
123 return(*this);
124 }
125
126 wxBitmap& operator=(const wxCursor& rCursor)
127 {
128 (void)CopyFromCursor(rCursor);
129 return (*this);
130 }
131
132 virtual ~wxBitmap();
133
134 wxImage ConvertToImage() const;
135
136 // get the given part of bitmap
137 wxBitmap GetSubBitmap(const wxRect& rRect) const;
138
139 // copies the contents and mask of the given (colour) icon to the bitmap
140 bool CopyFromIcon(const wxIcon& rIcon);
141
142 // copies the contents and mask of the given cursor to the bitmap
143 bool CopyFromCursor(const wxCursor& rCursor);
144
145 virtual bool Create( int nWidth
146 ,int nHeight
147 ,int nDepth = -1
148 );
149 virtual bool Create( void* pData
150 ,long lType
151 ,int nWidth
152 ,int nHeight
153 ,int nDepth = 1
154 );
155 virtual bool LoadFile( int nId
156 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
157 );
158 virtual bool LoadFile( const wxString& rName
159 ,long lType = wxBITMAP_TYPE_XPM
160 );
161 virtual bool SaveFile( const wxString& rName
162 ,int lType
163 ,const wxPalette* pCmap = NULL
164 );
165
166 inline wxBitmapRefData* GetBitmapData() const
167 { return (wxBitmapRefData *)m_refData; }
168
169 inline int GetQuality() const
170 { return (GetBitmapData() ? GetBitmapData()->m_nQuality : 0); }
171
172 void SetQuality(int nQ);
173
174 wxPalette* GetPalette() const
175 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette) : (wxPalette*) NULL); }
176
177 void SetPalette(const wxPalette& rPalette);
178
179 inline wxMask* GetMask() const
180 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask : (wxMask*) NULL); }
181
182 void SetMask(wxMask* pMask) ;
183
184 inline bool operator==(const wxBitmap& rBitmap) const
185 { return m_refData == rBitmap.m_refData; }
186
187 inline bool operator!=(const wxBitmap& rBitmap) const
188 { return m_refData != rBitmap.m_refData; }
189
190 // Implementation
191 public:
192 inline void SetHBITMAP(WXHBITMAP hBmp)
193 { SetHandle((WXHANDLE)hBmp); }
194
195 inline WXHBITMAP GetHBITMAP() const
196 { return (WXHBITMAP)GetHandle(); }
197
198 inline void SetSelectedInto(wxDC* pDc)
199 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
200
201 inline wxDC* GetSelectedInto() const
202 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
203
204 inline bool IsMono(void) const { return m_bIsMono; }
205
206 // An OS/2 version that probably doesn't do anything like the msw version
207 wxBitmap GetBitmapForDC(wxDC& rDc) const;
208
209 protected:
210 // common part of all ctors
211 void Init();
212
213 inline virtual wxGDIImageRefData* CreateData() const
214 { return new wxBitmapRefData; }
215
216 // creates the bitmap from XPM data, supposed to be called from ctor
217 bool CreateFromXpm(const char** ppData);
218 bool CreateFromImage(const wxImage& image, int depth);
219
220 private:
221 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
222
223 bool m_bIsMono;
224 DECLARE_DYNAMIC_CLASS(wxBitmap)
225 }; // end of CLASS wxBitmap
226
227 // ----------------------------------------------------------------------------
228 // wxMask: a mono bitmap used for drawing bitmaps transparently.
229 // ----------------------------------------------------------------------------
230
231 class WXDLLEXPORT wxMask : public wxObject
232 {
233 public:
234 wxMask();
235
236 // Construct a mask from a bitmap and a colour indicating the transparent
237 // area
238 wxMask( const wxBitmap& rBitmap
239 ,const wxColour& rColour
240 );
241
242 // Construct a mask from a bitmap and a palette index indicating the
243 // transparent area
244 wxMask( const wxBitmap& rBitmap
245 ,int nPaletteIndex
246 );
247
248 // Construct a mask from a mono bitmap (copies the bitmap).
249 wxMask(const wxBitmap& rBitmap);
250
251 // construct a mask from the givne bitmap handle
252 wxMask(WXHBITMAP hBmp)
253 { m_hMaskBitmap = hBmp; }
254
255 virtual ~wxMask();
256
257 bool Create( const wxBitmap& bitmap
258 ,const wxColour& rColour
259 );
260 bool Create( const wxBitmap& rBitmap
261 ,int nPaletteIndex
262 );
263 bool Create(const wxBitmap& rBitmap);
264
265 // Implementation
266 WXHBITMAP GetMaskBitmap() const
267 { return m_hMaskBitmap; }
268 void SetMaskBitmap(WXHBITMAP hBmp)
269 { m_hMaskBitmap = hBmp; }
270
271 protected:
272 WXHBITMAP m_hMaskBitmap;
273 DECLARE_DYNAMIC_CLASS(wxMask)
274 }; // end of CLASS wxMask
275
276 // ----------------------------------------------------------------------------
277 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
278 // ----------------------------------------------------------------------------
279
280 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
281 {
282 public:
283 inline wxBitmapHandler()
284 { m_lType = wxBITMAP_TYPE_INVALID; }
285
286 inline wxBitmapHandler( const wxString& rName
287 ,const wxString& rExt
288 ,long lType
289 )
290 : wxGDIImageHandler( rName
291 ,rExt
292 ,lType)
293 {
294 }
295
296 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
297 // old class which worked only with bitmaps
298 virtual bool Create( wxBitmap* pBitmap
299 ,void* pData
300 ,long lFlags
301 ,int nWidth
302 ,int nHeight
303 ,int nDepth = 1
304 );
305 virtual bool LoadFile( wxBitmap* pBitmap
306 ,int nId
307 ,long lFlags
308 ,int nDesiredWidth
309 ,int nDesiredHeight
310 );
311 virtual bool LoadFile( wxBitmap* pBitmap
312 ,const wxString& rName
313 ,long lFlags
314 ,int nDesiredWidth
315 ,int nDesiredHeight
316 );
317 virtual bool SaveFile( wxBitmap* pBitmap
318 ,const wxString& rName
319 ,int lType
320 ,const wxPalette* pPalette = NULL
321 );
322
323 virtual bool Create( wxGDIImage* pImage
324 ,void* pData
325 ,long lFlags
326 ,int nWidth
327 ,int nHeight
328 ,int nDepth = 1
329 );
330 virtual bool Load( wxGDIImage* pImage
331 ,int nId
332 ,long lFlags
333 ,int nDesiredWidth
334 ,int nDesiredHeight
335 );
336 virtual bool Save( wxGDIImage* pImage
337 ,const wxString& rName
338 ,int lType
339 );
340 private:
341 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
342 ,const wxString& WXUNUSED(rName)
343 ,HPS WXUNUSED(hPs)
344 ,long WXUNUSED(lFlags)
345 ,int WXUNUSED(nDesiredWidth)
346 ,int WXUNUSED(nDesiredHeight)
347 )
348 { return false; }
349 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
350 }; // end of CLASS wxBitmapHandler
351
352 #endif
353 // _WX_BITMAP_H_