]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/bitmap.h
changing to wxDC, so that wxGCDC can be used as well
[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 WXDLLIMPEXP_FWD_CORE wxDC;
21 class WXDLLIMPEXP_FWD_CORE wxControl;
22 class WXDLLIMPEXP_FWD_CORE wxBitmap;
23 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler;
24 class WXDLLIMPEXP_FWD_CORE wxIcon;
25 class WXDLLIMPEXP_FWD_CORE wxMask;
26 class WXDLLIMPEXP_FWD_CORE wxCursor;
27 class WXDLLIMPEXP_FWD_CORE wxControl;
28 class WXDLLIMPEXP_FWD_CORE 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 wxBitmapRefData(const wxBitmapRefData &tocopy);
42 virtual ~wxBitmapRefData() { Free(); }
43
44 virtual void Free();
45
46 public:
47 int m_nNumColors;
48 wxPalette m_vBitmapPalette;
49 int m_nQuality;
50
51 // OS2-specific
52 // ------------
53
54 wxDC* m_pSelectedInto;
55
56 //
57 // Optional mask for transparent drawing
58 //
59 wxMask* m_pBitmapMask;
60 }; // end of CLASS wxBitmapRefData
61
62 // ----------------------------------------------------------------------------
63 // wxBitmap: a mono or colour bitmap
64 // ----------------------------------------------------------------------------
65
66 class WXDLLEXPORT wxBitmap : public wxGDIImage
67 {
68 public:
69 // default ctor creates an invalid bitmap, you must Create() it later
70 wxBitmap() { Init(); }
71
72 // Copy constructors
73 inline wxBitmap(const wxBitmap& rBitmap)
74 : wxGDIImage(rBitmap)
75 {
76 Init();
77 SetHandle(rBitmap.GetHandle());
78 }
79
80 // Initialize with raw data
81 wxBitmap( const char bits[]
82 ,int nWidth
83 ,int nHeight
84 ,int nDepth = 1
85 );
86
87 // Initialize with XPM data
88 wxBitmap(const char* const* bits);
89 #ifdef wxNEEDS_CHARPP
90 // needed for old GCC
91 wxBitmap(char** data)
92 {
93 *this = wxBitmap(wx_const_cast(const char* const*, data));
94 }
95 #endif
96
97 // Load a resource
98 wxBitmap( int nId
99 ,long lType = wxBITMAP_TYPE_BMP_RESOURCE
100 );
101
102 // For compatiability with other ports, under OS/2 does same as default ctor
103 inline wxBitmap( const wxString& WXUNUSED(rFilename)
104 ,long WXUNUSED(lType)
105 )
106 { Init(); }
107 // New constructor for generalised creation from data
108 wxBitmap( const void* pData
109 ,long lType
110 ,int nWidth
111 ,int nHeight
112 ,int nDepth = 1
113 );
114
115 // If depth is omitted, will create a bitmap compatible with the display
116 wxBitmap( int nWidth, int nHeight, int nDepth = -1 );
117
118 wxBitmap( const wxImage& image, int depth = -1 )
119 { (void)CreateFromImage(image, depth); }
120
121 // we must have this, otherwise icons are silently copied into bitmaps using
122 // the copy ctor but the resulting bitmap is invalid!
123 inline wxBitmap(const wxIcon& rIcon)
124 { Init(); CopyFromIcon(rIcon); }
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( const 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 // Implementation
192 public:
193 inline void SetHBITMAP(WXHBITMAP hBmp)
194 { SetHandle((WXHANDLE)hBmp); }
195
196 inline WXHBITMAP GetHBITMAP() const
197 { return (WXHBITMAP)GetHandle(); }
198
199 inline void SetSelectedInto(wxDC* pDc)
200 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto = pDc; }
201
202 inline wxDC* GetSelectedInto() const
203 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto : (wxDC*) NULL); }
204
205 inline bool IsMono(void) const { return m_bIsMono; }
206
207 // An OS/2 version that probably doesn't do anything like the msw version
208 wxBitmap GetBitmapForDC(wxDC& rDc) const;
209
210 protected:
211 // common part of all ctors
212 void Init();
213
214 inline virtual wxGDIImageRefData* CreateData() const
215 { return new wxBitmapRefData; }
216
217 bool CreateFromImage(const wxImage& image, int depth);
218
219 virtual wxGDIRefData *CreateGDIRefData() const;
220 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
221
222 private:
223 bool CopyFromIconOrCursor(const wxGDIImage& rIcon);
224
225 bool m_bIsMono;
226 DECLARE_DYNAMIC_CLASS(wxBitmap)
227 }; // end of CLASS wxBitmap
228
229 // ----------------------------------------------------------------------------
230 // wxMask: a mono bitmap used for drawing bitmaps transparently.
231 // ----------------------------------------------------------------------------
232
233 class WXDLLEXPORT wxMask : public wxObject
234 {
235 public:
236 wxMask();
237 wxMask( const wxMask& tocopy);
238
239 // Construct a mask from a bitmap and a colour indicating the transparent
240 // area
241 wxMask( const wxBitmap& rBitmap
242 ,const wxColour& rColour
243 );
244
245 // Construct a mask from a bitmap and a palette index indicating the
246 // transparent area
247 wxMask( const wxBitmap& rBitmap
248 ,int nPaletteIndex
249 );
250
251 // Construct a mask from a mono bitmap (copies the bitmap).
252 wxMask(const wxBitmap& rBitmap);
253
254 // construct a mask from the givne bitmap handle
255 wxMask(WXHBITMAP hBmp)
256 { m_hMaskBitmap = hBmp; }
257
258 virtual ~wxMask();
259
260 bool Create( const wxBitmap& bitmap
261 ,const wxColour& rColour
262 );
263 bool Create( const wxBitmap& rBitmap
264 ,int nPaletteIndex
265 );
266 bool Create(const wxBitmap& rBitmap);
267
268 // Implementation
269 WXHBITMAP GetMaskBitmap() const
270 { return m_hMaskBitmap; }
271 void SetMaskBitmap(WXHBITMAP hBmp)
272 { m_hMaskBitmap = hBmp; }
273
274 protected:
275 WXHBITMAP m_hMaskBitmap;
276 DECLARE_DYNAMIC_CLASS(wxMask)
277 }; // end of CLASS wxMask
278
279 // ----------------------------------------------------------------------------
280 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
281 // ----------------------------------------------------------------------------
282
283 class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
284 {
285 public:
286 inline wxBitmapHandler()
287 { m_lType = wxBITMAP_TYPE_INVALID; }
288
289 inline wxBitmapHandler( const wxString& rName
290 ,const wxString& rExt
291 ,long lType
292 )
293 : wxGDIImageHandler( rName
294 ,rExt
295 ,lType)
296 {
297 }
298
299 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
300 // old class which worked only with bitmaps
301 virtual bool Create( wxBitmap* pBitmap
302 ,const void* pData
303 ,long lFlags
304 ,int nWidth
305 ,int nHeight
306 ,int nDepth = 1
307 );
308 virtual bool LoadFile( wxBitmap* pBitmap
309 ,int nId
310 ,long lFlags
311 ,int nDesiredWidth
312 ,int nDesiredHeight
313 );
314 virtual bool LoadFile( wxBitmap* pBitmap
315 ,const wxString& rName
316 ,long lFlags
317 ,int nDesiredWidth
318 ,int nDesiredHeight
319 );
320 virtual bool SaveFile( wxBitmap* pBitmap
321 ,const wxString& rName
322 ,int lType
323 ,const wxPalette* pPalette = NULL
324 );
325
326 virtual bool Create( wxGDIImage* pImage
327 ,const void* pData
328 ,long lFlags
329 ,int nWidth
330 ,int nHeight
331 ,int nDepth = 1
332 );
333 virtual bool Load( wxGDIImage* pImage
334 ,int nId
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 inline virtual bool Load( wxGDIImage* WXUNUSED(pImage)
345 ,const wxString& WXUNUSED(rName)
346 ,HPS WXUNUSED(hPs)
347 ,long WXUNUSED(lFlags)
348 ,int WXUNUSED(nDesiredWidth)
349 ,int WXUNUSED(nDesiredHeight)
350 )
351 { return false; }
352 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
353 }; // end of CLASS wxBitmapHandler
354
355 #endif
356 // _WX_BITMAP_H_