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 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 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 WXDLLEXPORT 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(wx_const_cast(const char* const*, data
));
99 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
102 // For compatiability with other ports, under OS/2 does same as default ctor
103 inline wxBitmap( const wxString
& WXUNUSED(rFilename
)
104 ,long 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 );
118 wxBitmap( const wxImage
& image
, int depth
= -1 )
119 { (void)CreateFromImage(image
, depth
); }
121 // we must have this, otherwise icons are silently copied into bitmaps using
122 // the copy ctor but the resulting bitmap is invalid!
123 inline wxBitmap(const wxIcon
& rIcon
)
124 { Init(); CopyFromIcon(rIcon
); }
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( const 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
) ;
193 inline void SetHBITMAP(WXHBITMAP hBmp
)
194 { SetHandle((WXHANDLE
)hBmp
); }
196 inline WXHBITMAP
GetHBITMAP() const
197 { return (WXHBITMAP
)GetHandle(); }
199 inline void SetSelectedInto(wxDC
* pDc
)
200 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
202 inline wxDC
* GetSelectedInto() const
203 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
205 inline bool IsMono(void) const { return m_bIsMono
; }
207 // An OS/2 version that probably doesn't do anything like the msw version
208 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
211 // common part of all ctors
214 inline virtual wxGDIImageRefData
* CreateData() const
215 { return new wxBitmapRefData
; }
217 bool CreateFromImage(const wxImage
& image
, int depth
);
219 virtual wxGDIRefData
*CloneGDIRefData(const wxGDIRefData
*data
) const;
222 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
225 DECLARE_DYNAMIC_CLASS(wxBitmap
)
226 }; // end of CLASS wxBitmap
228 // ----------------------------------------------------------------------------
229 // wxMask: a mono bitmap used for drawing bitmaps transparently.
230 // ----------------------------------------------------------------------------
232 class WXDLLEXPORT wxMask
: public wxObject
236 wxMask( const wxMask
& tocopy
);
238 // Construct a mask from a bitmap and a colour indicating the transparent
240 wxMask( const wxBitmap
& rBitmap
241 ,const wxColour
& rColour
244 // Construct a mask from a bitmap and a palette index indicating the
246 wxMask( const wxBitmap
& rBitmap
250 // Construct a mask from a mono bitmap (copies the bitmap).
251 wxMask(const wxBitmap
& rBitmap
);
253 // construct a mask from the givne bitmap handle
254 wxMask(WXHBITMAP hBmp
)
255 { m_hMaskBitmap
= hBmp
; }
259 bool Create( const wxBitmap
& bitmap
260 ,const wxColour
& rColour
262 bool Create( const wxBitmap
& rBitmap
265 bool Create(const wxBitmap
& rBitmap
);
268 WXHBITMAP
GetMaskBitmap() const
269 { return m_hMaskBitmap
; }
270 void SetMaskBitmap(WXHBITMAP hBmp
)
271 { m_hMaskBitmap
= hBmp
; }
274 WXHBITMAP m_hMaskBitmap
;
275 DECLARE_DYNAMIC_CLASS(wxMask
)
276 }; // end of CLASS wxMask
278 // ----------------------------------------------------------------------------
279 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
280 // ----------------------------------------------------------------------------
282 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
285 inline wxBitmapHandler()
286 { m_lType
= wxBITMAP_TYPE_INVALID
; }
288 inline wxBitmapHandler( const wxString
& rName
289 ,const wxString
& rExt
292 : wxGDIImageHandler( rName
298 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
299 // old class which worked only with bitmaps
300 virtual bool Create( wxBitmap
* pBitmap
307 virtual bool LoadFile( wxBitmap
* pBitmap
313 virtual bool LoadFile( wxBitmap
* pBitmap
314 ,const wxString
& rName
319 virtual bool SaveFile( wxBitmap
* pBitmap
320 ,const wxString
& rName
322 ,const wxPalette
* pPalette
= NULL
325 virtual bool Create( wxGDIImage
* pImage
332 virtual bool Load( wxGDIImage
* pImage
338 virtual bool Save( wxGDIImage
* pImage
339 ,const wxString
& rName
343 inline virtual bool Load( wxGDIImage
* WXUNUSED(pImage
)
344 ,const wxString
& WXUNUSED(rName
)
345 ,WXHANDLE
WXUNUSED(hPs
)
346 ,long WXUNUSED(lFlags
)
347 ,int WXUNUSED(nDesiredWidth
)
348 ,int WXUNUSED(nDesiredHeight
)
351 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
352 }; // end of CLASS wxBitmapHandler