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 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 wxPixelDataBase
;
30 // ----------------------------------------------------------------------------
33 // NB: this class is private, but declared here to make it possible inline
34 // wxBitmap functions accessing it
35 // ----------------------------------------------------------------------------
37 class WXDLLIMPEXP_CORE wxBitmapRefData
: public wxGDIImageRefData
41 wxBitmapRefData(const wxBitmapRefData
&tocopy
);
42 virtual ~wxBitmapRefData() { Free(); }
48 wxPalette m_vBitmapPalette
;
54 wxDC
* m_pSelectedInto
;
57 // Optional mask for transparent drawing
59 wxMask
* m_pBitmapMask
;
60 }; // end of CLASS wxBitmapRefData
62 // ----------------------------------------------------------------------------
63 // wxBitmap: a mono or colour bitmap
64 // ----------------------------------------------------------------------------
66 class WXDLLIMPEXP_CORE wxBitmap
: public wxGDIImage
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
); }
169 virtual bool Create( const void* pData
175 virtual bool LoadFile( int nId
176 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
178 virtual bool LoadFile( const wxString
& rName
179 ,wxBitmapType lType
= wxBITMAP_DEFAULT_TYPE
181 virtual bool SaveFile( const wxString
& rName
183 ,const wxPalette
* pCmap
= NULL
186 inline wxBitmapRefData
* GetBitmapData() const
187 { return (wxBitmapRefData
*)m_refData
; }
189 // raw bitmap access support functions
190 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
191 void UngetRawData(wxPixelDataBase
& data
);
193 inline int GetQuality() const
194 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
196 void SetQuality(int nQ
);
198 wxPalette
* GetPalette() const
199 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : NULL
); }
201 void SetPalette(const wxPalette
& rPalette
);
203 inline wxMask
* GetMask() const
204 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: NULL
); }
206 void SetMask(wxMask
* pMask
) ;
210 inline void SetHBITMAP(WXHBITMAP hBmp
)
211 { SetHandle((WXHANDLE
)hBmp
); }
213 inline WXHBITMAP
GetHBITMAP() const
214 { return (WXHBITMAP
)GetHandle(); }
216 inline void SetSelectedInto(wxDC
* pDc
)
217 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
219 inline wxDC
* GetSelectedInto() const
220 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: NULL
); }
222 inline bool IsMono(void) const { return m_bIsMono
; }
224 // An OS/2 version that probably doesn't do anything like the msw version
225 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
228 // common part of all ctors
231 inline virtual wxGDIImageRefData
* CreateData() const
232 { return new wxBitmapRefData
; }
234 bool CreateFromImage(const wxImage
& image
, int depth
);
236 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
239 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
242 DECLARE_DYNAMIC_CLASS(wxBitmap
)
243 }; // end of CLASS wxBitmap
245 // ----------------------------------------------------------------------------
246 // wxMask: a mono bitmap used for drawing bitmaps transparently.
247 // ----------------------------------------------------------------------------
249 class WXDLLIMPEXP_CORE wxMask
: public wxObject
253 wxMask( const wxMask
& tocopy
);
255 // Construct a mask from a bitmap and a colour indicating the transparent
257 wxMask( const wxBitmap
& rBitmap
258 ,const wxColour
& rColour
261 // Construct a mask from a bitmap and a palette index indicating the
263 wxMask( const wxBitmap
& rBitmap
267 // Construct a mask from a mono bitmap (copies the bitmap).
268 wxMask(const wxBitmap
& rBitmap
);
270 // construct a mask from the givne bitmap handle
271 wxMask(WXHBITMAP hBmp
)
272 { m_hMaskBitmap
= hBmp
; }
276 bool Create( const wxBitmap
& bitmap
277 ,const wxColour
& rColour
279 bool Create( const wxBitmap
& rBitmap
282 bool Create(const wxBitmap
& rBitmap
);
285 WXHBITMAP
GetMaskBitmap() const
286 { return m_hMaskBitmap
; }
287 void SetMaskBitmap(WXHBITMAP hBmp
)
288 { m_hMaskBitmap
= hBmp
; }
291 WXHBITMAP m_hMaskBitmap
;
292 DECLARE_DYNAMIC_CLASS(wxMask
)
293 }; // end of CLASS wxMask
295 // ----------------------------------------------------------------------------
296 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
297 // ----------------------------------------------------------------------------
299 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxGDIImageHandler
302 inline wxBitmapHandler()
303 { m_lType
= wxBITMAP_TYPE_INVALID
; }
305 inline wxBitmapHandler( const wxString
& rName
306 ,const wxString
& rExt
309 : wxGDIImageHandler( rName
315 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
316 // old class which worked only with bitmaps
317 virtual bool Create( wxBitmap
* pBitmap
324 virtual bool LoadFile( wxBitmap
* pBitmap
330 virtual bool LoadFile( wxBitmap
* pBitmap
331 ,const wxString
& rName
336 virtual bool SaveFile( wxBitmap
* pBitmap
337 ,const wxString
& rName
339 ,const wxPalette
* pPalette
= NULL
342 virtual bool Create( wxGDIImage
* pImage
349 virtual bool Load( wxGDIImage
* pImage
355 virtual bool Save( const wxGDIImage
* pImage
356 ,const wxString
& rName
360 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
361 ,const wxString
& WXUNUSED(rName
)
362 ,WXHANDLE
WXUNUSED(hPs
)
363 ,wxBitmapType
WXUNUSED(lFlags
)
364 ,int WXUNUSED(nDesiredWidth
)
365 ,int WXUNUSED(nDesiredHeight
)
368 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
369 }; // end of CLASS wxBitmapHandler