1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/os2/private.h"
15 #include "wx/os2/gdiimage.h"
16 #include "wx/gdicmn.h"
17 #include "wx/palette.h"
19 class WXDLLIMPEXP_FWD_CORE wxDC
;
20 class WXDLLIMPEXP_FWD_CORE wxControl
;
21 class WXDLLIMPEXP_FWD_CORE wxBitmap
;
22 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
23 class WXDLLIMPEXP_FWD_CORE wxIcon
;
24 class WXDLLIMPEXP_FWD_CORE wxMask
;
25 class WXDLLIMPEXP_FWD_CORE wxCursor
;
26 class WXDLLIMPEXP_FWD_CORE wxControl
;
27 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase
;
29 // ----------------------------------------------------------------------------
32 // NB: this class is private, but declared here to make it possible inline
33 // wxBitmap functions accessing it
34 // ----------------------------------------------------------------------------
36 class WXDLLIMPEXP_CORE wxBitmapRefData
: public wxGDIImageRefData
40 wxBitmapRefData(const wxBitmapRefData
&tocopy
);
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 WXDLLIMPEXP_CORE wxBitmap
: public wxGDIImage
,
66 public wxBitmapHelpers
69 // default ctor creates an invalid bitmap, you must Create() it later
70 wxBitmap() { Init(); }
73 inline wxBitmap(const wxBitmap
& rBitmap
)
77 SetHandle(rBitmap
.GetHandle());
80 // Initialize with raw data
81 wxBitmap( const char bits
[]
87 // Initialize with XPM data
88 wxBitmap(const char* const* bits
);
93 *this = wxBitmap(const_cast<const char* const*>(data
));
99 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
102 // For compatiability with other ports, under OS/2 does same as default ctor
103 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
104 ,wxBitmapType
WXUNUSED(lType
)
107 // New constructor for generalised creation from data
108 wxBitmap( const void* pData
115 // If depth is omitted, will create a bitmap compatible with the display
116 wxBitmap( int nWidth
, int nHeight
, int nDepth
= -1 )
119 (void)Create(nWidth
, nHeight
, nDepth
);
121 wxBitmap( const wxSize
& sz
, int nDepth
= -1 )
124 (void)Create(sz
, nDepth
);
127 wxBitmap( const wxImage
& image
, int depth
= -1 )
128 { (void)CreateFromImage(image
, depth
); }
130 // we must have this, otherwise icons are silently copied into bitmaps using
131 // the copy ctor but the resulting bitmap is invalid!
132 inline wxBitmap(const wxIcon
& rIcon
)
133 { Init(); CopyFromIcon(rIcon
); }
135 wxBitmap
& operator=(const wxIcon
& rIcon
)
137 (void)CopyFromIcon(rIcon
);
142 wxBitmap
& operator=(const wxCursor
& rCursor
)
144 (void)CopyFromCursor(rCursor
);
150 wxImage
ConvertToImage() const;
151 wxBitmap
ConvertToDisabled(unsigned char brightness
= 255) const;
153 // get the given part of bitmap
154 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
156 // copies the contents and mask of the given (colour) icon to the bitmap
157 bool CopyFromIcon(const wxIcon
& rIcon
);
159 // copies the contents and mask of the given cursor to the bitmap
160 bool CopyFromCursor(const wxCursor
& rCursor
);
162 virtual bool Create( int nWidth
164 ,int nDepth
= wxBITMAP_SCREEN_DEPTH
166 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
)
167 { return Create(sz
.GetWidth(), sz
.GetHeight(), depth
); }
168 virtual bool Create(int width
, int height
, const wxDC
& WXUNUSED(dc
))
169 { return Create(width
,height
); }
171 virtual bool Create( const void* pData
177 virtual bool LoadFile( int nId
178 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
180 virtual bool LoadFile( const wxString
& rName
181 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
183 virtual bool SaveFile( const wxString
& rName
185 ,const wxPalette
* pCmap
= NULL
188 inline wxBitmapRefData
* GetBitmapData() const
189 { return (wxBitmapRefData
*)m_refData
; }
191 // raw bitmap access support functions
192 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
193 void UngetRawData(wxPixelDataBase
& data
);
195 inline int GetQuality() const
196 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
198 void SetQuality(int nQ
);
200 wxPalette
* GetPalette() const
201 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : NULL
); }
203 void SetPalette(const wxPalette
& rPalette
);
205 inline wxMask
* GetMask() const
206 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: NULL
); }
208 void SetMask(wxMask
* pMask
) ;
212 inline void SetHBITMAP(WXHBITMAP hBmp
)
213 { SetHandle((WXHANDLE
)hBmp
); }
215 inline WXHBITMAP
GetHBITMAP() const
216 { return (WXHBITMAP
)GetHandle(); }
218 inline void SetSelectedInto(wxDC
* pDc
)
219 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
221 inline wxDC
* GetSelectedInto() const
222 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: NULL
); }
224 inline bool IsMono(void) const { return m_bIsMono
; }
226 // An OS/2 version that probably doesn't do anything like the msw version
227 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
230 // common part of all ctors
233 inline virtual wxGDIImageRefData
* CreateData() const
234 { return new wxBitmapRefData
; }
236 bool CreateFromImage(const wxImage
& image
, int depth
);
238 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
241 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
244 DECLARE_DYNAMIC_CLASS(wxBitmap
)
245 }; // end of CLASS wxBitmap
247 // ----------------------------------------------------------------------------
248 // wxMask: a mono bitmap used for drawing bitmaps transparently.
249 // ----------------------------------------------------------------------------
251 class WXDLLIMPEXP_CORE wxMask
: public wxObject
255 wxMask( const wxMask
& tocopy
);
257 // Construct a mask from a bitmap and a colour indicating the transparent
259 wxMask( const wxBitmap
& rBitmap
260 ,const wxColour
& rColour
263 // Construct a mask from a bitmap and a palette index indicating the
265 wxMask( const wxBitmap
& rBitmap
269 // Construct a mask from a mono bitmap (copies the bitmap).
270 wxMask(const wxBitmap
& rBitmap
);
272 // construct a mask from the givne bitmap handle
273 wxMask(WXHBITMAP hBmp
)
274 { m_hMaskBitmap
= hBmp
; }
278 bool Create( const wxBitmap
& bitmap
279 ,const wxColour
& rColour
281 bool Create( const wxBitmap
& rBitmap
284 bool Create(const wxBitmap
& rBitmap
);
287 WXHBITMAP
GetMaskBitmap() const
288 { return m_hMaskBitmap
; }
289 void SetMaskBitmap(WXHBITMAP hBmp
)
290 { m_hMaskBitmap
= hBmp
; }
293 WXHBITMAP m_hMaskBitmap
;
294 DECLARE_DYNAMIC_CLASS(wxMask
)
295 }; // end of CLASS wxMask
297 // ----------------------------------------------------------------------------
298 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
299 // ----------------------------------------------------------------------------
301 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxGDIImageHandler
304 inline wxBitmapHandler()
305 { m_lType
= wxBITMAP_TYPE_INVALID
; }
307 inline wxBitmapHandler( const wxString
& rName
308 ,const wxString
& rExt
311 : wxGDIImageHandler( rName
317 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
318 // old class which worked only with bitmaps
319 virtual bool Create( wxBitmap
* pBitmap
326 virtual bool LoadFile( wxBitmap
* pBitmap
332 virtual bool LoadFile( wxBitmap
* pBitmap
333 ,const wxString
& rName
338 virtual bool SaveFile( wxBitmap
* pBitmap
339 ,const wxString
& rName
341 ,const wxPalette
* pPalette
= NULL
344 virtual bool Create( wxGDIImage
* pImage
351 virtual bool Load( wxGDIImage
* pImage
357 virtual bool Save( const wxGDIImage
* pImage
358 ,const wxString
& rName
362 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
363 ,const wxString
& WXUNUSED(rName
)
364 ,WXHANDLE
WXUNUSED(hPs
)
365 ,wxBitmapType
WXUNUSED(lFlags
)
366 ,int WXUNUSED(nDesiredWidth
)
367 ,int WXUNUSED(nDesiredHeight
)
370 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
371 }; // end of CLASS wxBitmapHandler