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
)
73 { Init(); Ref(rBitmap
); SetHandle(rBitmap
.GetHandle()); }
75 // Initialize with raw data
76 wxBitmap( const char bits
[]
82 // Initialize with XPM data
83 wxBitmap(const char** ppData
) { CreateFromXpm(ppData
); }
84 wxBitmap(char** ppData
) { CreateFromXpm((const char**)ppData
); }
88 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
91 // For compatiability with other ports, under OS/2 does same as default ctor
92 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
96 // New constructor for generalised creation from data
104 // If depth is omitted, will create a bitmap compatible with the display
105 wxBitmap( int nWidth
, int nHeight
, int nDepth
= -1 );
107 wxBitmap( const wxImage
& image
, int depth
= -1 )
108 { (void)CreateFromImage(image
, depth
); }
110 // we must have this, otherwise icons are silently copied into bitmaps using
111 // the copy ctor but the resulting bitmap is invalid!
112 inline wxBitmap(const wxIcon
& rIcon
)
113 { Init(); CopyFromIcon(rIcon
); }
115 wxBitmap
& operator=(const wxBitmap
& rBitmap
)
117 if ( m_refData
!= rBitmap
.m_refData
)
122 wxBitmap
& operator=(const wxIcon
& rIcon
)
124 (void)CopyFromIcon(rIcon
);
129 wxBitmap
& operator=(const wxCursor
& rCursor
)
131 (void)CopyFromCursor(rCursor
);
137 wxImage
ConvertToImage() const;
139 // get the given part of bitmap
140 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
142 // copies the contents and mask of the given (colour) icon to the bitmap
143 bool CopyFromIcon(const wxIcon
& rIcon
);
145 // copies the contents and mask of the given cursor to the bitmap
146 bool CopyFromCursor(const wxCursor
& rCursor
);
148 virtual bool Create( int nWidth
152 virtual bool Create( void* pData
158 virtual bool LoadFile( int nId
159 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
161 virtual bool LoadFile( const wxString
& rName
162 ,long lType
= wxBITMAP_TYPE_XPM
164 virtual bool SaveFile( const wxString
& rName
166 ,const wxPalette
* pCmap
= NULL
169 inline wxBitmapRefData
* GetBitmapData() const
170 { return (wxBitmapRefData
*)m_refData
; }
172 inline int GetQuality() const
173 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
175 void SetQuality(int nQ
);
177 wxPalette
* GetPalette() const
178 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
180 void SetPalette(const wxPalette
& rPalette
);
182 inline wxMask
* GetMask() const
183 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
185 void SetMask(wxMask
* pMask
) ;
187 inline bool operator==(const wxBitmap
& rBitmap
) const
188 { return m_refData
== rBitmap
.m_refData
; }
190 inline bool operator!=(const wxBitmap
& rBitmap
) const
191 { return m_refData
!= rBitmap
.m_refData
; }
195 inline void SetHBITMAP(WXHBITMAP hBmp
)
196 { SetHandle((WXHANDLE
)hBmp
); }
198 inline WXHBITMAP
GetHBITMAP() const
199 { return (WXHBITMAP
)GetHandle(); }
201 inline void SetSelectedInto(wxDC
* pDc
)
202 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
204 inline wxDC
* GetSelectedInto() const
205 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
207 inline bool IsMono(void) const { return m_bIsMono
; }
209 // An OS/2 version that probably doesn't do anything like the msw version
210 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
213 // common part of all ctors
216 inline virtual wxGDIImageRefData
* CreateData() const
217 { return new wxBitmapRefData
; }
219 // creates the bitmap from XPM data, supposed to be called from ctor
220 bool CreateFromXpm(const char** ppData
);
221 bool CreateFromImage(const wxImage
& image
, int depth
);
224 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
227 DECLARE_DYNAMIC_CLASS(wxBitmap
)
228 }; // end of CLASS wxBitmap
230 // ----------------------------------------------------------------------------
231 // wxMask: a mono bitmap used for drawing bitmaps transparently.
232 // ----------------------------------------------------------------------------
234 class WXDLLEXPORT wxMask
: public wxObject
239 // Construct a mask from a bitmap and a colour indicating the transparent
241 wxMask( const wxBitmap
& rBitmap
242 ,const wxColour
& rColour
245 // Construct a mask from a bitmap and a palette index indicating the
247 wxMask( const wxBitmap
& rBitmap
251 // Construct a mask from a mono bitmap (copies the bitmap).
252 wxMask(const wxBitmap
& rBitmap
);
254 // construct a mask from the givne bitmap handle
255 wxMask(WXHBITMAP hBmp
)
256 { m_hMaskBitmap
= hBmp
; }
260 bool Create( const wxBitmap
& bitmap
261 ,const wxColour
& rColour
263 bool Create( const wxBitmap
& rBitmap
266 bool Create(const wxBitmap
& rBitmap
);
269 WXHBITMAP
GetMaskBitmap() const
270 { return m_hMaskBitmap
; }
271 void SetMaskBitmap(WXHBITMAP hBmp
)
272 { m_hMaskBitmap
= hBmp
; }
275 WXHBITMAP m_hMaskBitmap
;
276 DECLARE_DYNAMIC_CLASS(wxMask
)
277 }; // end of CLASS wxMask
279 // ----------------------------------------------------------------------------
280 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
281 // ----------------------------------------------------------------------------
283 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
286 inline wxBitmapHandler()
287 { m_lType
= wxBITMAP_TYPE_INVALID
; }
289 inline wxBitmapHandler( const wxString
& rName
290 ,const wxString
& rExt
293 : wxGDIImageHandler( rName
299 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
300 // old class which worked only with bitmaps
301 virtual bool Create( wxBitmap
* pBitmap
308 virtual bool LoadFile( wxBitmap
* pBitmap
314 virtual bool LoadFile( wxBitmap
* pBitmap
315 ,const wxString
& rName
320 virtual bool SaveFile( wxBitmap
* pBitmap
321 ,const wxString
& rName
323 ,const wxPalette
* pPalette
= NULL
326 virtual bool Create( wxGDIImage
* pImage
333 virtual bool Load( wxGDIImage
* pImage
339 virtual bool Save( wxGDIImage
* pImage
340 ,const wxString
& rName
344 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
345 ,const wxString
& WXUNUSED(rName
)
347 ,long WXUNUSED(lFlags
)
348 ,int WXUNUSED(nDesiredWidth
)
349 ,int WXUNUSED(nDesiredHeight
)
352 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
353 }; // end of CLASS wxBitmapHandler