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
;
60 // optional mask for transparent drawing
61 wxMask
* m_pBitmapMask
;
64 // ----------------------------------------------------------------------------
65 // wxBitmap: a mono or colour bitmap
66 // ----------------------------------------------------------------------------
68 class WXDLLEXPORT wxBitmap
: public wxGDIImage
71 // default ctor creates an invalid bitmap, you must Create() it later
72 wxBitmap() { Init(); }
75 inline wxBitmap(const wxBitmap
& rBitmap
)
76 { Init(); Ref(rBitmap
); }
78 // Initialize with raw data
79 wxBitmap( const char bits
[]
85 // Initialize with XPM data
86 wxBitmap( char** ppData
87 ,wxControl
* pAnItem
= NULL
90 // Load a file or resource
91 wxBitmap( const wxString
& rName
92 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
95 // New constructor for generalised creation from data
103 // If depth is omitted, will create a bitmap compatible with the display
109 // we must have this, otherwise icons are silently copied into bitmaps using
110 // the copy ctor but the resulting bitmap is invalid!
111 inline wxBitmap(const wxIcon
& rIcon
)
112 { Init(); CopyFromIcon(rIcon
); }
114 wxBitmap
& operator=(const wxBitmap
& rBitmap
)
116 if ( m_refData
!= rBitmap
.m_refData
)
121 wxBitmap
& operator=(const wxIcon
& rIcon
)
123 (void)CopyFromIcon(rIcon
);
128 wxBitmap
& operator=(const wxCursor
& rCursor
)
130 (void)CopyFromCursor(rCursor
);
136 // get the given part of bitmap
137 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
139 // copies the contents and mask of the given (colour) icon to the bitmap
140 bool CopyFromIcon(const wxIcon
& rIcon
);
142 // copies the contents and mask of the given cursor to the bitmap
143 bool CopyFromCursor(const wxCursor
& rCursor
);
145 virtual bool Create( int nWidth
149 virtual bool Create( void* pData
155 virtual bool LoadFile( const wxString
& rName
156 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
158 virtual bool SaveFile( const wxString
& rName
160 ,const wxPalette
* pCmap
= NULL
163 inline wxBitmapRefData
* GetBitmapData() const
164 { return (wxBitmapRefData
*)m_refData
; }
166 inline int GetQuality() const
167 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
169 void SetQuality(int nQ
);
171 wxPalette
* GetPalette() const
172 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
174 void SetPalette(const wxPalette
& rPalette
);
176 inline wxMask
* GetMask() const
177 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
179 void SetMask(wxMask
* pMask
) ;
181 inline bool operator==(const wxBitmap
& rBitmap
)
182 { return m_refData
== rBitmap
.m_refData
; }
184 inline bool operator!=(const wxBitmap
& rBitmap
)
185 { return m_refData
!= rBitmap
.m_refData
; }
187 #if WXWIN_COMPATIBILITY_2
188 void SetOk(bool bIsOk
);
189 #endif // WXWIN_COMPATIBILITY_2
191 #if WXWIN_COMPATIBILITY
192 inline wxPalette
* GetColourMap() const
193 { return GetPalette(); }
195 inline void SetColourMap(wxPalette
* pCmap
)
196 { SetPalette(*pCmap
); };
198 #endif // WXWIN_COMPATIBILITY
202 inline void SetHBITMAP(WXHBITMAP hBmp
)
203 { SetHandle((WXHANDLE
)hBmp
); }
205 inline WXHBITMAP
GetHBITMAP() const
206 { return (WXHBITMAP
)GetHandle(); }
208 inline void SetSelectedInto(wxDC
* pDc
)
209 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
211 inline wxDC
* GetSelectedInto() const
212 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
214 // An OS/2 version that probably doesn't do anything like the msw version
215 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
217 inline LONG
GetId() const
218 { return (GetBitmapData() ? GetBitmapData()->m_lId
: 0L); }
222 // common part of all ctors
225 inline virtual wxGDIImageRefData
* CreateData() const
226 { return new wxBitmapRefData
; }
228 // creates the bitmap from XPM data, supposed to be called from ctor
229 bool CreateFromXpm(const char **bits
);
232 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
234 DECLARE_DYNAMIC_CLASS(wxBitmap
)
235 }; // end of CLASS wxBitmap
237 // ----------------------------------------------------------------------------
238 // wxMask: a mono bitmap used for drawing bitmaps transparently.
239 // ----------------------------------------------------------------------------
241 class WXDLLEXPORT wxMask
: public wxObject
246 // Construct a mask from a bitmap and a colour indicating the transparent
248 wxMask( const wxBitmap
& rBitmap
249 ,const wxColour
& rColour
252 // Construct a mask from a bitmap and a palette index indicating the
254 wxMask( const wxBitmap
& rBitmap
258 // Construct a mask from a mono bitmap (copies the bitmap).
259 wxMask(const wxBitmap
& rBitmap
);
261 // construct a mask from the givne bitmap handle
262 wxMask(WXHBITMAP hBmp
)
263 { m_hMaskBitmap
= hBmp
; }
267 bool Create( const wxBitmap
& bitmap
268 ,const wxColour
& rColour
270 bool Create( const wxBitmap
& rBitmap
273 bool Create(const wxBitmap
& rBitmap
);
276 WXHBITMAP
GetMaskBitmap() const
277 { return m_hMaskBitmap
; }
278 void SetMaskBitmap(WXHBITMAP hBmp
)
279 { m_hMaskBitmap
= hBmp
; }
282 WXHBITMAP m_hMaskBitmap
;
283 DECLARE_DYNAMIC_CLASS(wxMask
)
289 // ----------------------------------------------------------------------------
290 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
291 // ----------------------------------------------------------------------------
293 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
296 inline wxBitmapHandler()
297 { m_lType
= wxBITMAP_TYPE_INVALID
; }
299 inline wxBitmapHandler( const wxString
& rName
300 ,const wxString
& rExt
303 : wxGDIImageHandler( rName
309 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
310 // old class which worked only with bitmaps
311 virtual bool Create( wxBitmap
* pBitmap
318 virtual bool LoadFile( wxBitmap
* pBitmap
319 ,const wxString
& rName
325 virtual bool SaveFile( wxBitmap
* pBitmap
326 ,const wxString
& rName
328 ,const wxPalette
* pPalette
= NULL
331 virtual bool Create( wxGDIImage
* pImage
338 virtual bool Load( wxGDIImage
* pImage
339 ,const wxString
& rName
345 virtual bool Save( wxGDIImage
* pImage
346 ,const wxString
& rName
350 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
351 }; // end of wxBitmapHandler