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
;
32 class WXDLLEXPORT wxImage
;
34 // ----------------------------------------------------------------------------
37 // NB: this class is private, but declared here to make it possible inline
38 // wxBitmap functions accessing it
39 // ----------------------------------------------------------------------------
41 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
45 virtual ~wxBitmapRefData() { Free(); }
51 wxPalette m_vBitmapPalette
;
57 wxDC
* m_pSelectedInto
;
60 // Optional mask for transparent drawing
62 wxMask
* m_pBitmapMask
;
63 }; // end of CLASS wxBitmapRefData
65 // ----------------------------------------------------------------------------
66 // wxBitmap: a mono or colour bitmap
67 // ----------------------------------------------------------------------------
69 class WXDLLEXPORT wxBitmap
: public wxGDIImage
72 // default ctor creates an invalid bitmap, you must Create() it later
73 wxBitmap() { Init(); }
76 inline wxBitmap(const wxBitmap
& rBitmap
)
77 { Init(); Ref(rBitmap
); 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 wxBitmap
& rBitmap
)
121 if ( m_refData
!= rBitmap
.m_refData
)
126 wxBitmap
& operator=(const wxIcon
& rIcon
)
128 (void)CopyFromIcon(rIcon
);
133 wxBitmap
& operator=(const wxCursor
& rCursor
)
135 (void)CopyFromCursor(rCursor
);
141 wxImage
ConvertToImage() const;
143 // get the given part of bitmap
144 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
146 // copies the contents and mask of the given (colour) icon to the bitmap
147 bool CopyFromIcon(const wxIcon
& rIcon
);
149 // copies the contents and mask of the given cursor to the bitmap
150 bool CopyFromCursor(const wxCursor
& rCursor
);
152 virtual bool Create( int nWidth
156 virtual bool Create( void* pData
162 virtual bool LoadFile( int nId
163 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
165 virtual bool SaveFile( const wxString
& rName
167 ,const wxPalette
* pCmap
= NULL
170 inline wxBitmapRefData
* GetBitmapData() const
171 { return (wxBitmapRefData
*)m_refData
; }
173 inline int GetQuality() const
174 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
176 void SetQuality(int nQ
);
178 wxPalette
* GetPalette() const
179 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
181 void SetPalette(const wxPalette
& rPalette
);
183 inline wxMask
* GetMask() const
184 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
186 void SetMask(wxMask
* pMask
) ;
188 inline bool operator==(const wxBitmap
& rBitmap
) const
189 { return m_refData
== rBitmap
.m_refData
; }
191 inline bool operator!=(const wxBitmap
& rBitmap
) const
192 { return m_refData
!= rBitmap
.m_refData
; }
196 inline void SetHBITMAP(WXHBITMAP hBmp
)
197 { SetHandle((WXHANDLE
)hBmp
); }
199 inline WXHBITMAP
GetHBITMAP() const
200 { return (WXHBITMAP
)GetHandle(); }
202 inline void SetSelectedInto(wxDC
* pDc
)
203 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
205 inline wxDC
* GetSelectedInto() const
206 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
208 inline bool IsMono(void) const { return m_bIsMono
; }
210 // An OS/2 version that probably doesn't do anything like the msw version
211 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
214 // common part of all ctors
217 inline virtual wxGDIImageRefData
* CreateData() const
218 { return new wxBitmapRefData
; }
220 // creates the bitmap from XPM data, supposed to be called from ctor
221 bool CreateFromXpm(const char** ppData
);
222 bool CreateFromImage(const wxImage
& image
, int depth
);
225 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
228 DECLARE_DYNAMIC_CLASS(wxBitmap
)
229 }; // end of 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
)
278 }; // end of CLASS wxMask
280 // ----------------------------------------------------------------------------
281 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
282 // ----------------------------------------------------------------------------
284 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
287 inline wxBitmapHandler()
288 { m_lType
= wxBITMAP_TYPE_INVALID
; }
290 inline wxBitmapHandler( const wxString
& rName
291 ,const wxString
& rExt
294 : wxGDIImageHandler( rName
300 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
301 // old class which worked only with bitmaps
302 virtual bool Create( wxBitmap
* pBitmap
309 virtual bool LoadFile( wxBitmap
* pBitmap
315 virtual bool SaveFile( wxBitmap
* pBitmap
316 ,const wxString
& rName
318 ,const wxPalette
* pPalette
= NULL
321 virtual bool Create( wxGDIImage
* pImage
328 virtual bool Load( wxGDIImage
* pImage
334 virtual bool Save( wxGDIImage
* pImage
335 ,const wxString
& rName
339 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
340 ,const wxString
& WXUNUSED(rName
)
342 ,long WXUNUSED(lFlags
)
343 ,int WXUNUSED(nDesiredWidth
)
344 ,int WXUNUSED(nDesiredHeight
)
347 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
348 }; // end of CLASS wxBitmapHandler