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 LoadFile( const wxString
& rName
166 ,long lType
= wxBITMAP_TYPE_XPM
168 virtual bool SaveFile( const wxString
& rName
170 ,const wxPalette
* pCmap
= NULL
173 inline wxBitmapRefData
* GetBitmapData() const
174 { return (wxBitmapRefData
*)m_refData
; }
176 inline int GetQuality() const
177 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
179 void SetQuality(int nQ
);
181 wxPalette
* GetPalette() const
182 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
184 void SetPalette(const wxPalette
& rPalette
);
186 inline wxMask
* GetMask() const
187 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
189 void SetMask(wxMask
* pMask
) ;
191 inline bool operator==(const wxBitmap
& rBitmap
) const
192 { return m_refData
== rBitmap
.m_refData
; }
194 inline bool operator!=(const wxBitmap
& rBitmap
) const
195 { return m_refData
!= rBitmap
.m_refData
; }
199 inline void SetHBITMAP(WXHBITMAP hBmp
)
200 { SetHandle((WXHANDLE
)hBmp
); }
202 inline WXHBITMAP
GetHBITMAP() const
203 { return (WXHBITMAP
)GetHandle(); }
205 inline void SetSelectedInto(wxDC
* pDc
)
206 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
208 inline wxDC
* GetSelectedInto() const
209 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
211 inline bool IsMono(void) const { return m_bIsMono
; }
213 // An OS/2 version that probably doesn't do anything like the msw version
214 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
217 // common part of all ctors
220 inline virtual wxGDIImageRefData
* CreateData() const
221 { return new wxBitmapRefData
; }
223 // creates the bitmap from XPM data, supposed to be called from ctor
224 bool CreateFromXpm(const char** ppData
);
225 bool CreateFromImage(const wxImage
& image
, int depth
);
228 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
231 DECLARE_DYNAMIC_CLASS(wxBitmap
)
232 }; // end of CLASS wxBitmap
234 // ----------------------------------------------------------------------------
235 // wxMask: a mono bitmap used for drawing bitmaps transparently.
236 // ----------------------------------------------------------------------------
238 class WXDLLEXPORT wxMask
: public wxObject
243 // Construct a mask from a bitmap and a colour indicating the transparent
245 wxMask( const wxBitmap
& rBitmap
246 ,const wxColour
& rColour
249 // Construct a mask from a bitmap and a palette index indicating the
251 wxMask( const wxBitmap
& rBitmap
255 // Construct a mask from a mono bitmap (copies the bitmap).
256 wxMask(const wxBitmap
& rBitmap
);
258 // construct a mask from the givne bitmap handle
259 wxMask(WXHBITMAP hBmp
)
260 { m_hMaskBitmap
= hBmp
; }
264 bool Create( const wxBitmap
& bitmap
265 ,const wxColour
& rColour
267 bool Create( const wxBitmap
& rBitmap
270 bool Create(const wxBitmap
& rBitmap
);
273 WXHBITMAP
GetMaskBitmap() const
274 { return m_hMaskBitmap
; }
275 void SetMaskBitmap(WXHBITMAP hBmp
)
276 { m_hMaskBitmap
= hBmp
; }
279 WXHBITMAP m_hMaskBitmap
;
280 DECLARE_DYNAMIC_CLASS(wxMask
)
281 }; // end of CLASS wxMask
283 // ----------------------------------------------------------------------------
284 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
285 // ----------------------------------------------------------------------------
287 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
290 inline wxBitmapHandler()
291 { m_lType
= wxBITMAP_TYPE_INVALID
; }
293 inline wxBitmapHandler( const wxString
& rName
294 ,const wxString
& rExt
297 : wxGDIImageHandler( rName
303 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
304 // old class which worked only with bitmaps
305 virtual bool Create( wxBitmap
* pBitmap
312 virtual bool LoadFile( wxBitmap
* pBitmap
318 virtual bool LoadFile( wxBitmap
* pBitmap
319 ,const wxString
& rName
324 virtual bool SaveFile( wxBitmap
* pBitmap
325 ,const wxString
& rName
327 ,const wxPalette
* pPalette
= NULL
330 virtual bool Create( wxGDIImage
* pImage
337 virtual bool Load( wxGDIImage
* pImage
343 virtual bool Save( wxGDIImage
* pImage
344 ,const wxString
& rName
348 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
349 ,const wxString
& WXUNUSED(rName
)
351 ,long WXUNUSED(lFlags
)
352 ,int WXUNUSED(nDesiredWidth
)
353 ,int WXUNUSED(nDesiredHeight
)
356 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
357 }; // end of CLASS wxBitmapHandler