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 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "bitmap.h"
19 #include "wx/os2/private.h"
20 #include "wx/os2/gdiimage.h"
21 #include "wx/gdicmn.h"
22 #include "wx/palette.h"
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
;
33 // ----------------------------------------------------------------------------
36 // NB: this class is private, but declared here to make it possible inline
37 // wxBitmap functions accessing it
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
44 virtual ~wxBitmapRefData() { Free(); }
50 wxPalette m_vBitmapPalette
;
56 wxDC
* m_pSelectedInto
;
57 HPS m_hPresentationSpace
;
60 // optional mask for transparent drawing
61 wxMask
* m_pBitmapMask
;
64 // ----------------------------------------------------------------------------
65 // wxBitmap: a mono or colour bitmap
66 // ----------------------------------------------------------------------------
68 class WXDLLEXPORT wxBitmap
: public wxGDIImage
71 // default ctor creates an invalid bitmap, you must Create() it later
72 wxBitmap() { Init(); }
75 inline wxBitmap(const wxBitmap
& rBitmap
)
76 { Init(); Ref(rBitmap
); }
78 // Initialize with raw data
79 wxBitmap( const char bits
[]
85 // Initialize with XPM data
86 wxBitmap( char** ppData
87 ,wxControl
* pAnItem
= NULL
90 // Load a file or resource
91 wxBitmap( const wxString
& rName
92 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
95 // New constructor for generalised creation from data
103 // If depth is omitted, will create a bitmap compatible with the display
109 // we must have this, otherwise icons are silently copied into bitmaps using
110 // the copy ctor but the resulting bitmap is invalid!
111 inline wxBitmap(const wxIcon
& rIcon
)
112 { Init(); CopyFromIcon(rIcon
); }
114 wxBitmap
& operator=(const wxBitmap
& rBitmap
)
116 if ( m_refData
!= rBitmap
.m_refData
)
121 wxBitmap
& operator=(const wxIcon
& rIcon
)
123 (void)CopyFromIcon(rIcon
);
128 wxBitmap
& operator=(const wxCursor
& rCursor
)
130 (void)CopyFromCursor(rCursor
);
136 // copies the contents and mask of the given (colour) icon to the bitmap
137 bool CopyFromIcon(const wxIcon
& rIcon
);
139 // copies the contents and mask of the given cursor to the bitmap
140 bool CopyFromCursor(const wxCursor
& rCursor
);
142 virtual bool Create( int nWidth
146 virtual bool Create( void* pData
152 virtual bool LoadFile( const wxString
& rName
153 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
155 virtual bool SaveFile( const wxString
& rName
157 ,const wxPalette
* pCmap
= NULL
160 inline wxBitmapRefData
* GetBitmapData() const
161 { return (wxBitmapRefData
*)m_refData
; }
163 inline int GetQuality() const
164 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
166 void SetQuality(int nQ
);
168 wxPalette
* GetPalette() const
169 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
171 void SetPalette(const wxPalette
& rPalette
);
173 inline wxMask
* GetMask() const
174 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
176 void SetMask(wxMask
* pMask
) ;
178 inline bool operator==(const wxBitmap
& rBitmap
)
179 { return m_refData
== rBitmap
.m_refData
; }
181 inline bool operator!=(const wxBitmap
& rBitmap
)
182 { return m_refData
!= rBitmap
.m_refData
; }
184 #if WXWIN_COMPATIBILITY_2
185 void SetOk(bool bIsOk
);
186 #endif // WXWIN_COMPATIBILITY_2
188 #if WXWIN_COMPATIBILITY
189 inline wxPalette
* GetColourMap() const
190 { return GetPalette(); }
192 inline void SetColourMap(wxPalette
* pCmap
)
193 { SetPalette(*pCmap
); };
195 #endif // WXWIN_COMPATIBILITY
199 inline void SetHBITMAP(WXHBITMAP hBmp
)
200 { SetHandle((WXHANDLE
)hBmp
); }
202 inline WXHBITMAP
GetHBITMAP() const
203 { return (WXHBITMAP
)GetHandle(); }
205 inline void SetSelectedInto(wxDC
* pDc
)
206 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
208 inline wxDC
* GetSelectedInto() const
209 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
211 // An OS/2 version that probably doesn't do anything like the msw version
212 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
214 inline LONG
GetId() const
215 { return (GetBitmapData() ? GetBitmapData()->m_lId
: 0L); }
219 // common part of all ctors
222 inline virtual wxGDIImageRefData
* CreateData() const
223 { return new wxBitmapRefData
; }
226 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
228 DECLARE_DYNAMIC_CLASS(wxBitmap
)
231 // ----------------------------------------------------------------------------
232 // wxMask: a mono bitmap used for drawing bitmaps transparently.
233 // ----------------------------------------------------------------------------
235 class WXDLLEXPORT wxMask
: public wxObject
240 // Construct a mask from a bitmap and a colour indicating the transparent
242 wxMask( const wxBitmap
& rBitmap
243 ,const wxColour
& rColour
246 // Construct a mask from a bitmap and a palette index indicating the
248 wxMask( const wxBitmap
& rBitmap
252 // Construct a mask from a mono bitmap (copies the bitmap).
253 wxMask(const wxBitmap
& rBitmap
);
255 // construct a mask from the givne bitmap handle
256 wxMask(WXHBITMAP hBmp
)
257 { m_hMaskBitmap
= hBmp
; }
261 bool Create( const wxBitmap
& bitmap
262 ,const wxColour
& rColour
264 bool Create( const wxBitmap
& rBitmap
267 bool Create(const wxBitmap
& rBitmap
);
270 WXHBITMAP
GetMaskBitmap() const
271 { return m_hMaskBitmap
; }
272 void SetMaskBitmap(WXHBITMAP hBmp
)
273 { m_hMaskBitmap
= hBmp
; }
276 WXHBITMAP m_hMaskBitmap
;
277 DECLARE_DYNAMIC_CLASS(wxMask
)
283 // ----------------------------------------------------------------------------
284 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
285 // ----------------------------------------------------------------------------
287 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
290 inline wxBitmapHandler()
291 { m_lType
= wxBITMAP_TYPE_INVALID
; }
293 inline wxBitmapHandler( const wxString
& rName
294 ,const wxString
& rExt
297 : wxGDIImageHandler( rName
303 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
304 // old class which worked only with bitmaps
305 virtual bool Create( wxBitmap
* pBitmap
312 virtual bool LoadFile( wxBitmap
* pBitmap
313 ,const wxString
& rName
319 virtual bool SaveFile( wxBitmap
* pBitmap
320 ,const wxString
& rName
322 ,const wxPalette
* pPalette
= NULL
325 virtual bool Create( wxGDIImage
* pImage
332 virtual bool Load( wxGDIImage
* pImage
333 ,const wxString
& rName
339 virtual bool Save( wxGDIImage
* pImage
340 ,const wxString
& rName
344 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)