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** ppData
) { CreateFromXpm(ppData
); }
88 wxBitmap(char** ppData
) { CreateFromXpm((const char**)ppData
); }
92 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
95 // For compatiability with other ports, under OS/2 does same as default ctor
96 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
100 // New constructor for generalised creation from data
101 wxBitmap( void* pData
108 // If depth is omitted, will create a bitmap compatible with the display
109 wxBitmap( int nWidth
, int nHeight
, int nDepth
= -1 );
111 wxBitmap( const wxImage
& image
, int depth
= -1 )
112 { (void)CreateFromImage(image
, depth
); }
114 // we must have this, otherwise icons are silently copied into bitmaps using
115 // the copy ctor but the resulting bitmap is invalid!
116 inline wxBitmap(const wxIcon
& rIcon
)
117 { Init(); CopyFromIcon(rIcon
); }
119 wxBitmap
& operator=(const wxIcon
& rIcon
)
121 (void)CopyFromIcon(rIcon
);
126 wxBitmap
& operator=(const wxCursor
& rCursor
)
128 (void)CopyFromCursor(rCursor
);
134 wxImage
ConvertToImage() const;
136 // get the given part of bitmap
137 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
139 // copies the contents and mask of the given (colour) icon to the bitmap
140 bool CopyFromIcon(const wxIcon
& rIcon
);
142 // copies the contents and mask of the given cursor to the bitmap
143 bool CopyFromCursor(const wxCursor
& rCursor
);
145 virtual bool Create( int nWidth
149 virtual bool Create( void* pData
155 virtual bool LoadFile( int nId
156 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
158 virtual bool LoadFile( const wxString
& rName
159 ,long lType
= wxBITMAP_TYPE_XPM
161 virtual bool SaveFile( const wxString
& rName
163 ,const wxPalette
* pCmap
= NULL
166 inline wxBitmapRefData
* GetBitmapData() const
167 { return (wxBitmapRefData
*)m_refData
; }
169 inline int GetQuality() const
170 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
172 void SetQuality(int nQ
);
174 wxPalette
* GetPalette() const
175 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
177 void SetPalette(const wxPalette
& rPalette
);
179 inline wxMask
* GetMask() const
180 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
182 void SetMask(wxMask
* pMask
) ;
184 inline bool operator==(const wxBitmap
& rBitmap
) const
185 { return m_refData
== rBitmap
.m_refData
; }
187 inline bool operator!=(const wxBitmap
& rBitmap
) const
188 { return m_refData
!= rBitmap
.m_refData
; }
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 // creates the bitmap from XPM data, supposed to be called from ctor
217 bool CreateFromXpm(const char** ppData
);
218 bool CreateFromImage(const wxImage
& image
, int depth
);
221 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
224 DECLARE_DYNAMIC_CLASS(wxBitmap
)
225 }; // end of CLASS wxBitmap
227 // ----------------------------------------------------------------------------
228 // wxMask: a mono bitmap used for drawing bitmaps transparently.
229 // ----------------------------------------------------------------------------
231 class WXDLLEXPORT wxMask
: public wxObject
236 // Construct a mask from a bitmap and a colour indicating the transparent
238 wxMask( const wxBitmap
& rBitmap
239 ,const wxColour
& rColour
242 // Construct a mask from a bitmap and a palette index indicating the
244 wxMask( const wxBitmap
& rBitmap
248 // Construct a mask from a mono bitmap (copies the bitmap).
249 wxMask(const wxBitmap
& rBitmap
);
251 // construct a mask from the givne bitmap handle
252 wxMask(WXHBITMAP hBmp
)
253 { m_hMaskBitmap
= hBmp
; }
257 bool Create( const wxBitmap
& bitmap
258 ,const wxColour
& rColour
260 bool Create( const wxBitmap
& rBitmap
263 bool Create(const wxBitmap
& rBitmap
);
266 WXHBITMAP
GetMaskBitmap() const
267 { return m_hMaskBitmap
; }
268 void SetMaskBitmap(WXHBITMAP hBmp
)
269 { m_hMaskBitmap
= hBmp
; }
272 WXHBITMAP m_hMaskBitmap
;
273 DECLARE_DYNAMIC_CLASS(wxMask
)
274 }; // end of CLASS wxMask
276 // ----------------------------------------------------------------------------
277 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
278 // ----------------------------------------------------------------------------
280 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
283 inline wxBitmapHandler()
284 { m_lType
= wxBITMAP_TYPE_INVALID
; }
286 inline wxBitmapHandler( const wxString
& rName
287 ,const wxString
& rExt
290 : wxGDIImageHandler( rName
296 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
297 // old class which worked only with bitmaps
298 virtual bool Create( wxBitmap
* pBitmap
305 virtual bool LoadFile( wxBitmap
* pBitmap
311 virtual bool LoadFile( wxBitmap
* pBitmap
312 ,const wxString
& rName
317 virtual bool SaveFile( wxBitmap
* pBitmap
318 ,const wxString
& rName
320 ,const wxPalette
* pPalette
= NULL
323 virtual bool Create( wxGDIImage
* pImage
330 virtual bool Load( wxGDIImage
* pImage
336 virtual bool Save( wxGDIImage
* pImage
337 ,const wxString
& rName
341 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
342 ,const wxString
& WXUNUSED(rName
)
344 ,long WXUNUSED(lFlags
)
345 ,int WXUNUSED(nDesiredWidth
)
346 ,int WXUNUSED(nDesiredHeight
)
349 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
350 }; // end of CLASS wxBitmapHandler