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
;
33 // ----------------------------------------------------------------------------
36 // NB: this class is private, but declared here to make it possible inline
37 // wxBitmap functions accessing it
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
44 virtual ~wxBitmapRefData() { Free(); }
50 wxPalette m_vBitmapPalette
;
56 wxDC
* m_pSelectedInto
;
57 HPS m_hPresentationSpace
;
59 // optional mask for transparent drawing
60 wxMask
* m_pBitmapMask
;
63 // ----------------------------------------------------------------------------
64 // wxBitmap: a mono or colour bitmap
65 // ----------------------------------------------------------------------------
67 class WXDLLEXPORT wxBitmap
: public wxGDIImage
70 // default ctor creates an invalid bitmap, you must Create() it later
71 wxBitmap() { Init(); }
74 inline wxBitmap(const wxBitmap
& rBitmap
)
75 { Init(); Ref(rBitmap
); }
77 // Initialize with raw data
78 wxBitmap( const char bits
[]
84 // Initialize with XPM data
85 wxBitmap( char** ppData
86 ,wxControl
* pAnItem
= NULL
89 // Load a file or resource
90 wxBitmap( const wxString
& rName
91 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
94 // New constructor for generalised creation from data
102 // If depth is omitted, will create a bitmap compatible with the display
108 // we must have this, otherwise icons are silently copied into bitmaps using
109 // the copy ctor but the resulting bitmap is invalid!
110 inline wxBitmap(const wxIcon
& rIcon
)
111 { Init(); CopyFromIcon(rIcon
); }
113 wxBitmap
& operator=(const wxBitmap
& rBitmap
)
115 if ( m_refData
!= rBitmap
.m_refData
)
120 wxBitmap
& operator=(const wxIcon
& rIcon
)
122 (void)CopyFromIcon(rIcon
);
127 wxBitmap
& operator=(const wxCursor
& rCursor
)
129 (void)CopyFromCursor(rCursor
);
135 // copies the contents and mask of the given (colour) icon to the bitmap
136 bool CopyFromIcon(const wxIcon
& rIcon
);
138 // copies the contents and mask of the given cursor to the bitmap
139 bool CopyFromCursor(const wxCursor
& rCursor
);
141 virtual bool Create( int nWidth
145 virtual bool Create( void* pData
151 virtual bool LoadFile( const wxString
& rName
152 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
154 virtual bool SaveFile( const wxString
& rName
156 ,const wxPalette
* pCmap
= NULL
159 inline wxBitmapRefData
* GetBitmapData() const
160 { return (wxBitmapRefData
*)m_refData
; }
162 inline int GetQuality() const
163 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
165 void SetQuality(int nQ
);
167 wxPalette
* GetPalette() const
168 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
170 void SetPalette(const wxPalette
& rPalette
);
172 inline wxMask
* GetMask() const
173 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
175 void SetMask(wxMask
* pMask
) ;
177 inline bool operator==(const wxBitmap
& rBitmap
)
178 { return m_refData
== rBitmap
.m_refData
; }
180 inline bool operator!=(const wxBitmap
& rBitmap
)
181 { return m_refData
!= rBitmap
.m_refData
; }
183 #if WXWIN_COMPATIBILITY_2
184 void SetOk(bool bIsOk
);
185 #endif // WXWIN_COMPATIBILITY_2
187 #if WXWIN_COMPATIBILITY
188 inline wxPalette
* GetColourMap() const
189 { return GetPalette(); }
191 inline void SetColourMap(wxPalette
* pCmap
)
192 { SetPalette(*pCmap
); };
194 #endif // WXWIN_COMPATIBILITY
198 inline void SetHBITMAP(WXHBITMAP hBmp
)
199 { SetHandle((WXHANDLE
)hBmp
); }
201 inline WXHBITMAP
GetHBITMAP() const
202 { return (WXHBITMAP
)GetHandle(); }
204 inline void SetSelectedInto(wxDC
* pDc
)
205 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
207 inline wxDC
* GetSelectedInto() const
208 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
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
; }
221 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
223 DECLARE_DYNAMIC_CLASS(wxBitmap
)
226 // ----------------------------------------------------------------------------
227 // wxMask: a mono bitmap used for drawing bitmaps transparently.
228 // ----------------------------------------------------------------------------
230 class WXDLLEXPORT wxMask
: public wxObject
235 // Construct a mask from a bitmap and a colour indicating the transparent
237 wxMask( const wxBitmap
& rBitmap
238 ,const wxColour
& rColour
241 // Construct a mask from a bitmap and a palette index indicating the
243 wxMask( const wxBitmap
& rBitmap
247 // Construct a mask from a mono bitmap (copies the bitmap).
248 wxMask(const wxBitmap
& rBitmap
);
250 // construct a mask from the givne bitmap handle
251 wxMask(WXHBITMAP hBmp
)
252 { m_hMaskBitmap
= hBmp
; }
256 bool Create( const wxBitmap
& bitmap
257 ,const wxColour
& rColour
259 bool Create( const wxBitmap
& rBitmap
262 bool Create(const wxBitmap
& rBitmap
);
265 WXHBITMAP
GetMaskBitmap() const
266 { return m_hMaskBitmap
; }
267 void SetMaskBitmap(WXHBITMAP hBmp
)
268 { m_hMaskBitmap
= hBmp
; }
271 WXHBITMAP m_hMaskBitmap
;
272 DECLARE_DYNAMIC_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
308 ,const wxString
& rName
313 virtual bool SaveFile( wxBitmap
* pBitmap
314 ,const wxString
& rName
316 ,const wxPalette
* pPalette
= NULL
319 virtual bool Create( wxGDIImage
* pImage
326 virtual bool Load( wxGDIImage
* pImage
327 ,const wxString
& rName
332 virtual bool Save( wxGDIImage
* pImage
333 ,const wxString
& rName
337 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)