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* const* bits
);
91 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
94 // For compatiability with other ports, under OS/2 does same as default ctor
95 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
99 // New constructor for generalised creation from data
100 wxBitmap( const void* pData
107 // If depth is omitted, will create a bitmap compatible with the display
108 wxBitmap( int nWidth
, int nHeight
, int nDepth
= -1 );
110 wxBitmap( const wxImage
& image
, int depth
= -1 )
111 { (void)CreateFromImage(image
, depth
); }
113 // we must have this, otherwise icons are silently copied into bitmaps using
114 // the copy ctor but the resulting bitmap is invalid!
115 inline wxBitmap(const wxIcon
& rIcon
)
116 { Init(); CopyFromIcon(rIcon
); }
118 wxBitmap
& operator=(const wxIcon
& rIcon
)
120 (void)CopyFromIcon(rIcon
);
125 wxBitmap
& operator=(const wxCursor
& rCursor
)
127 (void)CopyFromCursor(rCursor
);
133 wxImage
ConvertToImage() const;
135 // get the given part of bitmap
136 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
138 // copies the contents and mask of the given (colour) icon to the bitmap
139 bool CopyFromIcon(const wxIcon
& rIcon
);
141 // copies the contents and mask of the given cursor to the bitmap
142 bool CopyFromCursor(const wxCursor
& rCursor
);
144 virtual bool Create( int nWidth
148 virtual bool Create( const void* pData
154 virtual bool LoadFile( int nId
155 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
157 virtual bool LoadFile( const wxString
& rName
158 ,long lType
= wxBITMAP_TYPE_XPM
160 virtual bool SaveFile( const wxString
& rName
162 ,const wxPalette
* pCmap
= NULL
165 inline wxBitmapRefData
* GetBitmapData() const
166 { return (wxBitmapRefData
*)m_refData
; }
168 inline int GetQuality() const
169 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
171 void SetQuality(int nQ
);
173 wxPalette
* GetPalette() const
174 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
176 void SetPalette(const wxPalette
& rPalette
);
178 inline wxMask
* GetMask() const
179 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
181 void SetMask(wxMask
* pMask
) ;
183 inline bool operator==(const wxBitmap
& rBitmap
) const
184 { return m_refData
== rBitmap
.m_refData
; }
186 inline bool operator!=(const wxBitmap
& rBitmap
) const
187 { return m_refData
!= rBitmap
.m_refData
; }
191 inline void SetHBITMAP(WXHBITMAP hBmp
)
192 { SetHandle((WXHANDLE
)hBmp
); }
194 inline WXHBITMAP
GetHBITMAP() const
195 { return (WXHBITMAP
)GetHandle(); }
197 inline void SetSelectedInto(wxDC
* pDc
)
198 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
200 inline wxDC
* GetSelectedInto() const
201 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
203 inline bool IsMono(void) const { return m_bIsMono
; }
205 // An OS/2 version that probably doesn't do anything like the msw version
206 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
209 // common part of all ctors
212 inline virtual wxGDIImageRefData
* CreateData() const
213 { return new wxBitmapRefData
; }
215 bool CreateFromImage(const wxImage
& image
, int depth
);
218 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
221 DECLARE_DYNAMIC_CLASS(wxBitmap
)
222 }; // end of CLASS wxBitmap
224 // ----------------------------------------------------------------------------
225 // wxMask: a mono bitmap used for drawing bitmaps transparently.
226 // ----------------------------------------------------------------------------
228 class WXDLLEXPORT wxMask
: public wxObject
233 // Construct a mask from a bitmap and a colour indicating the transparent
235 wxMask( const wxBitmap
& rBitmap
236 ,const wxColour
& rColour
239 // Construct a mask from a bitmap and a palette index indicating the
241 wxMask( const wxBitmap
& rBitmap
245 // Construct a mask from a mono bitmap (copies the bitmap).
246 wxMask(const wxBitmap
& rBitmap
);
248 // construct a mask from the givne bitmap handle
249 wxMask(WXHBITMAP hBmp
)
250 { m_hMaskBitmap
= hBmp
; }
254 bool Create( const wxBitmap
& bitmap
255 ,const wxColour
& rColour
257 bool Create( const wxBitmap
& rBitmap
260 bool Create(const wxBitmap
& rBitmap
);
263 WXHBITMAP
GetMaskBitmap() const
264 { return m_hMaskBitmap
; }
265 void SetMaskBitmap(WXHBITMAP hBmp
)
266 { m_hMaskBitmap
= hBmp
; }
269 WXHBITMAP m_hMaskBitmap
;
270 DECLARE_DYNAMIC_CLASS(wxMask
)
271 }; // end of CLASS wxMask
273 // ----------------------------------------------------------------------------
274 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
275 // ----------------------------------------------------------------------------
277 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
280 inline wxBitmapHandler()
281 { m_lType
= wxBITMAP_TYPE_INVALID
; }
283 inline wxBitmapHandler( const wxString
& rName
284 ,const wxString
& rExt
287 : wxGDIImageHandler( rName
293 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
294 // old class which worked only with bitmaps
295 virtual bool Create( wxBitmap
* pBitmap
302 virtual bool LoadFile( wxBitmap
* pBitmap
308 virtual bool LoadFile( wxBitmap
* pBitmap
309 ,const wxString
& rName
314 virtual bool SaveFile( wxBitmap
* pBitmap
315 ,const wxString
& rName
317 ,const wxPalette
* pPalette
= NULL
320 virtual bool Create( wxGDIImage
* pImage
327 virtual bool Load( wxGDIImage
* pImage
333 virtual bool Save( wxGDIImage
* pImage
334 ,const wxString
& rName
338 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
339 ,const wxString
& WXUNUSED(rName
)
341 ,long WXUNUSED(lFlags
)
342 ,int WXUNUSED(nDesiredWidth
)
343 ,int WXUNUSED(nDesiredHeight
)
346 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
347 }; // end of CLASS wxBitmapHandler