1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/os2/private.h"
16 #include "wx/os2/gdiimage.h"
17 #include "wx/gdicmn.h"
18 #include "wx/palette.h"
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
;
30 // ----------------------------------------------------------------------------
33 // NB: this class is private, but declared here to make it possible inline
34 // wxBitmap functions accessing it
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
41 virtual ~wxBitmapRefData() { Free(); }
47 wxPalette m_vBitmapPalette
;
53 wxDC
* m_pSelectedInto
;
56 // Optional mask for transparent drawing
58 wxMask
* m_pBitmapMask
;
59 }; // end of CLASS wxBitmapRefData
61 // ----------------------------------------------------------------------------
62 // wxBitmap: a mono or colour bitmap
63 // ----------------------------------------------------------------------------
65 class WXDLLEXPORT wxBitmap
: public wxGDIImage
68 // default ctor creates an invalid bitmap, you must Create() it later
69 wxBitmap() { Init(); }
72 inline wxBitmap(const wxBitmap
& rBitmap
)
76 SetHandle(rBitmap
.GetHandle());
79 // Initialize with raw data
80 wxBitmap( const char bits
[]
86 // Initialize with XPM data
87 wxBitmap(const char* const* bits
);
88 #if defined (__GNUC__) && __GNUC__ < 3
92 *this = wxBitmap(wx_const_cast(const char* const*, data
));
98 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
101 // For compatiability with other ports, under OS/2 does same as default ctor
102 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
103 ,long WXUNUSED(lType
)
106 // New constructor for generalised creation from data
107 wxBitmap( const void* pData
114 // If depth is omitted, will create a bitmap compatible with the display
115 wxBitmap( int nWidth
, int nHeight
, int nDepth
= -1 );
117 wxBitmap( const wxImage
& image
, int depth
= -1 )
118 { (void)CreateFromImage(image
, depth
); }
120 // we must have this, otherwise icons are silently copied into bitmaps using
121 // the copy ctor but the resulting bitmap is invalid!
122 inline wxBitmap(const wxIcon
& rIcon
)
123 { Init(); CopyFromIcon(rIcon
); }
125 wxBitmap
& operator=(const wxIcon
& rIcon
)
127 (void)CopyFromIcon(rIcon
);
132 wxBitmap
& operator=(const wxCursor
& rCursor
)
134 (void)CopyFromCursor(rCursor
);
140 wxImage
ConvertToImage() const;
142 // get the given part of bitmap
143 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
145 // copies the contents and mask of the given (colour) icon to the bitmap
146 bool CopyFromIcon(const wxIcon
& rIcon
);
148 // copies the contents and mask of the given cursor to the bitmap
149 bool CopyFromCursor(const wxCursor
& rCursor
);
151 virtual bool Create( int nWidth
155 virtual bool Create( const void* pData
161 virtual bool LoadFile( int nId
162 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
164 virtual bool LoadFile( const wxString
& rName
165 ,long lType
= wxBITMAP_TYPE_XPM
167 virtual bool SaveFile( const wxString
& rName
169 ,const wxPalette
* pCmap
= NULL
172 inline wxBitmapRefData
* GetBitmapData() const
173 { return (wxBitmapRefData
*)m_refData
; }
175 inline int GetQuality() const
176 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
178 void SetQuality(int nQ
);
180 wxPalette
* GetPalette() const
181 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
183 void SetPalette(const wxPalette
& rPalette
);
185 inline wxMask
* GetMask() const
186 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
188 void SetMask(wxMask
* pMask
) ;
192 inline void SetHBITMAP(WXHBITMAP hBmp
)
193 { SetHandle((WXHANDLE
)hBmp
); }
195 inline WXHBITMAP
GetHBITMAP() const
196 { return (WXHBITMAP
)GetHandle(); }
198 inline void SetSelectedInto(wxDC
* pDc
)
199 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
201 inline wxDC
* GetSelectedInto() const
202 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
204 inline bool IsMono(void) const { return m_bIsMono
; }
206 // An OS/2 version that probably doesn't do anything like the msw version
207 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
210 // common part of all ctors
213 inline virtual wxGDIImageRefData
* CreateData() const
214 { return new wxBitmapRefData
; }
216 bool CreateFromImage(const wxImage
& image
, int depth
);
219 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
222 DECLARE_DYNAMIC_CLASS(wxBitmap
)
223 }; // end of CLASS wxBitmap
225 // ----------------------------------------------------------------------------
226 // wxMask: a mono bitmap used for drawing bitmaps transparently.
227 // ----------------------------------------------------------------------------
229 class WXDLLEXPORT wxMask
: public wxObject
234 // Construct a mask from a bitmap and a colour indicating the transparent
236 wxMask( const wxBitmap
& rBitmap
237 ,const wxColour
& rColour
240 // Construct a mask from a bitmap and a palette index indicating the
242 wxMask( const wxBitmap
& rBitmap
246 // Construct a mask from a mono bitmap (copies the bitmap).
247 wxMask(const wxBitmap
& rBitmap
);
249 // construct a mask from the givne bitmap handle
250 wxMask(WXHBITMAP hBmp
)
251 { m_hMaskBitmap
= hBmp
; }
255 bool Create( const wxBitmap
& bitmap
256 ,const wxColour
& rColour
258 bool Create( const wxBitmap
& rBitmap
261 bool Create(const wxBitmap
& rBitmap
);
264 WXHBITMAP
GetMaskBitmap() const
265 { return m_hMaskBitmap
; }
266 void SetMaskBitmap(WXHBITMAP hBmp
)
267 { m_hMaskBitmap
= hBmp
; }
270 WXHBITMAP m_hMaskBitmap
;
271 DECLARE_DYNAMIC_CLASS(wxMask
)
272 }; // end of CLASS wxMask
274 // ----------------------------------------------------------------------------
275 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
276 // ----------------------------------------------------------------------------
278 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
281 inline wxBitmapHandler()
282 { m_lType
= wxBITMAP_TYPE_INVALID
; }
284 inline wxBitmapHandler( const wxString
& rName
285 ,const wxString
& rExt
288 : wxGDIImageHandler( rName
294 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
295 // old class which worked only with bitmaps
296 virtual bool Create( wxBitmap
* pBitmap
303 virtual bool LoadFile( wxBitmap
* pBitmap
309 virtual bool LoadFile( wxBitmap
* pBitmap
310 ,const wxString
& rName
315 virtual bool SaveFile( wxBitmap
* pBitmap
316 ,const wxString
& rName
318 ,const wxPalette
* pPalette
= NULL
321 virtual bool Create( wxGDIImage
* pImage
328 virtual bool Load( wxGDIImage
* pImage
334 virtual bool Save( wxGDIImage
* pImage
335 ,const wxString
& rName
339 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
340 ,const wxString
& WXUNUSED(rName
)
342 ,long WXUNUSED(lFlags
)
343 ,int WXUNUSED(nDesiredWidth
)
344 ,int WXUNUSED(nDesiredHeight
)
347 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
348 }; // end of CLASS wxBitmapHandler