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/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
23 class WXDLLEXPORT wxDC
;
24 class WXDLLEXPORT wxControl
;
25 class WXDLLEXPORT wxBitmap
;
26 class WXDLLEXPORT wxBitmapHandler
;
27 class WXDLLEXPORT wxIcon
;
28 class WXDLLEXPORT wxMask
;
29 class WXDLLEXPORT wxCursor
;
30 class WXDLLEXPORT wxControl
;
32 // ----------------------------------------------------------------------------
35 // NB: this class is private, but declared here to make it possible inline
36 // wxBitmap functions accessing it
37 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
43 virtual ~wxBitmapRefData() { Free(); }
49 wxPalette m_vBitmapPalette
;
55 wxDC
* m_pSelectedInto
;
56 HPS m_hPresentationSpace
;
58 // optional mask for transparent drawing
59 wxMask
* m_pBitmapMask
;
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
)
74 { Init(); Ref(rBitmap
); }
76 // Initialize with raw data
77 wxBitmap( const char bits
[]
83 // Initialize with XPM data
84 wxBitmap( char** ppData
85 ,wxControl
* pAnItem
= NULL
88 // Load a file or resource
89 wxBitmap( const wxString
& rName
90 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
93 // New constructor for generalised creation from data
101 // If depth is omitted, will create a bitmap compatible with the display
107 // we must have this, otherwise icons are silently copied into bitmaps using
108 // the copy ctor but the resulting bitmap is invalid!
109 inline wxBitmap(const wxIcon
& rIcon
)
110 { Init(); CopyFromIcon(rIcon
); }
112 wxBitmap
& operator=(const wxBitmap
& rBitmap
)
114 if ( m_refData
!= rBitmap
.m_refData
)
119 wxBitmap
& operator=(const wxIcon
& rIcon
)
121 (void)CopyFromIcon(rIcon
);
126 wxBitmap
& operator=(const wxCursor
& rCursor
)
128 (void)CopyFromCursor(rCursor
);
134 // copies the contents and mask of the given (colour) icon to the bitmap
135 bool CopyFromIcon(const wxIcon
& rIcon
);
137 // copies the contents and mask of the given cursor to the bitmap
138 bool CopyFromCursor(const wxCursor
& rCursor
);
140 virtual bool Create( int nWidth
144 virtual bool Create( void* pData
150 virtual bool LoadFile( const wxString
& rName
151 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
153 virtual bool SaveFile( const wxString
& rName
155 ,const wxPalette
* pCmap
= NULL
158 inline wxBitmapRefData
* GetBitmapData() const
159 { return (wxBitmapRefData
*)m_refData
; }
161 inline int GetQuality() const
162 { return (GetBitmapData() ? GetBitmapData()->m_quality
: 0); }
164 void SetQuality(int nQ
);
166 wxPalette
* GetPalette() const
167 { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette
) : (wxPalette
*) NULL
); }
169 void SetPalette(const wxPalette
& rPalette
);
171 inline wxMask
* GetMask() const
172 { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask
: (wxMask
*) NULL
); }
174 void SetMask(wxMask
* pMask
) ;
176 inline bool operator==(const wxBitmap
& rBitmap
)
177 { return m_refData
== rBitmap
.m_refData
; }
179 inline bool operator!=(const wxBitmap
& rBitmap
)
180 { return m_refData
!= rBitmap
.m_refData
; }
182 #if WXWIN_COMPATIBILITY_2
183 void SetOk(bool bIsOk
);
184 #endif // WXWIN_COMPATIBILITY_2
186 #if WXWIN_COMPATIBILITY
187 inline wxPalette
* GetColourMap() const
188 { return GetPalette(); }
190 inline void SetColourMap(wxPalette
* pCmap
)
191 { SetPalette(*pCmap
); };
193 #endif // WXWIN_COMPATIBILITY
197 inline void SetHBITMAP(WXHBITMAP hHmp
)
198 { SetHandle((WXHANDLE
)bmp
); }
200 inline WXHBITMAP
GetHBITMAP() const
201 { return (WXHBITMAP
)GetHandle(); }
203 inline void SetSelectedInto(wxDC
* pDc
)
204 { if (GetBitmapData()) GetBitmapData()->m_selectedInto
= pDc
; }
206 inline wxDC
* GetSelectedInto() const
207 { return (GetBitmapData() ? GetBitmapData()->m_selectedInto
: (wxDC
*) NULL
); }
209 // Creates a bitmap that matches the device context's depth, from an
210 // arbitray bitmap. At present, the original bitmap must have an associated
211 // palette. (TODO: use a default palette if no palette exists.) This
212 // function is necessary for you to Blit an arbitrary bitmap (which may
213 // have the wrong depth). wxDC::SelectObject will compare the depth of the
214 // bitmap with the DC's depth, and create a new bitmap if the depths
215 // differ. Eventually we should perhaps make this a public API function so
216 // that an app can efficiently produce bitmaps of the correct depth. The
217 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
218 // to a DC, but this is too Windows-specific, hence this solution of
219 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
220 // <frederic.villeneuve@natinst.com>
221 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
224 // common part of all ctors
227 inline virtual wxGDIImageRefData
* CreateData() const
228 { return new wxBitmapRefData
; }
231 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
233 DECLARE_DYNAMIC_CLASS(wxBitmap
)
236 // ----------------------------------------------------------------------------
237 // wxMask: a mono bitmap used for drawing bitmaps transparently.
238 // ----------------------------------------------------------------------------
240 class WXDLLEXPORT wxMask
: public wxObject
245 // Construct a mask from a bitmap and a colour indicating the transparent
247 wxMask( const wxBitmap
& rBitmap
248 ,const wxColour
& rColour
251 // Construct a mask from a bitmap and a palette index indicating the
253 wxMask( const wxBitmap
& rBitmap
257 // Construct a mask from a mono bitmap (copies the bitmap).
258 wxMask(const wxBitmap
& rBitmap
);
260 // construct a mask from the givne bitmap handle
261 wxMask(WXHBITMAP hBmp
)
262 { m_hMaskBitmap
= hBmp
; }
266 bool Create( const wxBitmap
& bitmap
267 ,const wxColour
& rColour
269 bool Create( const wxBitmap
& rBitmap
272 bool Create(const wxBitmap
& rBitmap
);
275 WXHBITMAP
GetMaskBitmap() const
276 { return m_hMaskBitmap
; }
277 void SetMaskBitmap(WXHBITMAP hBmp
)
278 { m_hMaskBitmap
= hBmp
; }
281 WXHBITMAP m_hMaskBitmap
;
282 DECLARE_DYNAMIC_CLASS(wxMask
)
285 // ----------------------------------------------------------------------------
286 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
287 // ----------------------------------------------------------------------------
289 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
292 inline wxBitmapHandler()
293 { m_lType
= wxBITMAP_TYPE_INVALID
; }
295 inline wxBitmapHandler( const wxString
& rName
296 ,const wxString
& rExt
299 : wxGDIImageHandler( rName
305 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
306 // old class which worked only with bitmaps
307 virtual bool Create( wxBitmap
* pBitmap
314 virtual bool LoadFile( wxBitmap
* pBitmap
315 ,const wxString
& rName
320 virtual bool SaveFile( wxBitmap
* pBitmap
321 ,const wxString
& rName
323 ,const wxPalette
* pPalette
= NULL
326 virtual bool Create( wxGDIImage
* pImage
333 virtual bool Load( wxGDIImage
* pImage
334 ,const wxString
& rName
339 virtual bool Save(wxGDIImage
* pImage
340 const wxString
& rName
344 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)