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
);
225 DECLARE_DYNAMIC_CLASS(wxBitmap
)
228 // ----------------------------------------------------------------------------
229 // wxMask: a mono bitmap used for drawing bitmaps transparently.
230 // ----------------------------------------------------------------------------
232 class WXDLLEXPORT wxMask
: public wxObject
237 // Construct a mask from a bitmap and a colour indicating the transparent
239 wxMask( const wxBitmap
& rBitmap
240 ,const wxColour
& rColour
243 // Construct a mask from a bitmap and a palette index indicating the
245 wxMask( const wxBitmap
& rBitmap
249 // Construct a mask from a mono bitmap (copies the bitmap).
250 wxMask(const wxBitmap
& rBitmap
);
252 // construct a mask from the givne bitmap handle
253 wxMask(WXHBITMAP hBmp
)
254 { m_hMaskBitmap
= hBmp
; }
258 bool Create( const wxBitmap
& bitmap
259 ,const wxColour
& rColour
261 bool Create( const wxBitmap
& rBitmap
264 bool Create(const wxBitmap
& rBitmap
);
267 WXHBITMAP
GetMaskBitmap() const
268 { return m_hMaskBitmap
; }
269 void SetMaskBitmap(WXHBITMAP hBmp
)
270 { m_hMaskBitmap
= hBmp
; }
273 WXHBITMAP m_hMaskBitmap
;
274 DECLARE_DYNAMIC_CLASS(wxMask
)
277 // ----------------------------------------------------------------------------
278 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
279 // ----------------------------------------------------------------------------
281 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
284 inline wxBitmapHandler()
285 { m_lType
= wxBITMAP_TYPE_INVALID
; }
287 inline wxBitmapHandler( const wxString
& rName
288 ,const wxString
& rExt
291 : wxGDIImageHandler( rName
297 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
298 // old class which worked only with bitmaps
299 virtual bool Create( wxBitmap
* pBitmap
306 virtual bool LoadFile( wxBitmap
* pBitmap
307 ,const wxString
& rName
312 virtual bool SaveFile( wxBitmap
* pBitmap
313 ,const wxString
& rName
315 ,const wxPalette
* pPalette
= NULL
318 virtual bool Create( wxGDIImage
* pImage
325 virtual bool Load( wxGDIImage
* pImage
326 ,const wxString
& rName
331 virtual bool Save( wxGDIImage
* pImage
332 ,const wxString
& rName
336 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)