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
;
32 class WXDLLEXPORT wxImage
;
34 // ----------------------------------------------------------------------------
37 // NB: this class is private, but declared here to make it possible inline
38 // wxBitmap functions accessing it
39 // ----------------------------------------------------------------------------
41 class WXDLLEXPORT wxBitmapRefData
: public wxGDIImageRefData
45 virtual ~wxBitmapRefData() { Free(); }
51 wxPalette m_vBitmapPalette
;
57 wxDC
* m_pSelectedInto
;
60 // Optional mask for transparent drawing
62 wxMask
* m_pBitmapMask
;
63 }; // end of CLASS wxBitmapRefData
65 // ----------------------------------------------------------------------------
66 // wxBitmap: a mono or colour bitmap
67 // ----------------------------------------------------------------------------
69 class WXDLLEXPORT wxBitmap
: public wxGDIImage
72 // default ctor creates an invalid bitmap, you must Create() it later
73 wxBitmap() { Init(); }
76 inline wxBitmap(const wxBitmap
& rBitmap
)
77 { Init(); Ref(rBitmap
); }
79 // Initialize with raw data
80 wxBitmap( const char bits
[]
86 // Initialize with XPM data
87 wxBitmap(const char** ppData
) { CreateFromXpm(ppData
); }
88 wxBitmap(char** ppData
) { CreateFromXpm((const char**)ppData
); }
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 wxBitmap( const wxImage
& image
, int depth
= -1 )
110 { (void)CreateFromImage(image
, depth
); }
112 // we must have this, otherwise icons are silently copied into bitmaps using
113 // the copy ctor but the resulting bitmap is invalid!
114 inline wxBitmap(const wxIcon
& rIcon
)
115 { Init(); CopyFromIcon(rIcon
); }
117 wxBitmap
& operator=(const wxBitmap
& rBitmap
)
119 if ( m_refData
!= rBitmap
.m_refData
)
124 wxBitmap
& operator=(const wxIcon
& rIcon
)
126 (void)CopyFromIcon(rIcon
);
131 wxBitmap
& operator=(const wxCursor
& rCursor
)
133 (void)CopyFromCursor(rCursor
);
139 wxImage
ConvertToImage() const;
141 // get the given part of bitmap
142 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
144 // copies the contents and mask of the given (colour) icon to the bitmap
145 bool CopyFromIcon(const wxIcon
& rIcon
);
147 // copies the contents and mask of the given cursor to the bitmap
148 bool CopyFromCursor(const wxCursor
& rCursor
);
150 virtual bool Create( int nWidth
154 virtual bool Create( void* pData
160 virtual bool LoadFile( const wxString
& rName
161 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
163 virtual bool SaveFile( const wxString
& rName
165 ,const wxPalette
* pCmap
= NULL
168 inline wxBitmapRefData
* GetBitmapData() const
169 { return (wxBitmapRefData
*)m_refData
; }
171 inline int GetQuality() const
172 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
174 void SetQuality(int nQ
);
176 wxPalette
* GetPalette() const
177 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
179 void SetPalette(const wxPalette
& rPalette
);
181 inline wxMask
* GetMask() const
182 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
184 void SetMask(wxMask
* pMask
) ;
186 inline bool operator==(const wxBitmap
& rBitmap
) const
187 { return m_refData
== rBitmap
.m_refData
; }
189 inline bool operator!=(const wxBitmap
& rBitmap
) const
190 { return m_refData
!= rBitmap
.m_refData
; }
192 #if WXWIN_COMPATIBILITY_2
193 void SetOk(bool bIsOk
);
194 #endif // WXWIN_COMPATIBILITY_2
196 #if WXWIN_COMPATIBILITY
197 inline wxPalette
* GetColourMap() const
198 { return GetPalette(); }
200 inline void SetColourMap(wxPalette
* pCmap
)
201 { SetPalette(*pCmap
); };
203 #endif // WXWIN_COMPATIBILITY
207 inline void SetHBITMAP(WXHBITMAP hBmp
)
208 { SetHandle((WXHANDLE
)hBmp
); }
210 inline WXHBITMAP
GetHBITMAP() const
211 { return (WXHBITMAP
)GetHandle(); }
213 inline void SetSelectedInto(wxDC
* pDc
)
214 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
216 inline wxDC
* GetSelectedInto() const
217 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
219 // An OS/2 version that probably doesn't do anything like the msw version
220 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
222 // inline LONG GetId() const
223 // { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); }
227 // common part of all ctors
230 inline virtual wxGDIImageRefData
* CreateData() const
231 { return new wxBitmapRefData
; }
233 // creates the bitmap from XPM data, supposed to be called from ctor
234 bool CreateFromXpm(const char** ppData
);
235 bool CreateFromImage(const wxImage
& image
, int depth
);
238 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
240 DECLARE_DYNAMIC_CLASS(wxBitmap
)
241 }; // end of CLASS wxBitmap
243 // ----------------------------------------------------------------------------
244 // wxMask: a mono bitmap used for drawing bitmaps transparently.
245 // ----------------------------------------------------------------------------
247 class WXDLLEXPORT wxMask
: public wxObject
252 // Construct a mask from a bitmap and a colour indicating the transparent
254 wxMask( const wxBitmap
& rBitmap
255 ,const wxColour
& rColour
258 // Construct a mask from a bitmap and a palette index indicating the
260 wxMask( const wxBitmap
& rBitmap
264 // Construct a mask from a mono bitmap (copies the bitmap).
265 wxMask(const wxBitmap
& rBitmap
);
267 // construct a mask from the givne bitmap handle
268 wxMask(WXHBITMAP hBmp
)
269 { m_hMaskBitmap
= hBmp
; }
273 bool Create( const wxBitmap
& bitmap
274 ,const wxColour
& rColour
276 bool Create( const wxBitmap
& rBitmap
279 bool Create(const wxBitmap
& rBitmap
);
282 WXHBITMAP
GetMaskBitmap() const
283 { return m_hMaskBitmap
; }
284 void SetMaskBitmap(WXHBITMAP hBmp
)
285 { m_hMaskBitmap
= hBmp
; }
288 WXHBITMAP m_hMaskBitmap
;
289 DECLARE_DYNAMIC_CLASS(wxMask
)
290 }; // end of CLASS wxMask
292 // ----------------------------------------------------------------------------
293 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
294 // ----------------------------------------------------------------------------
296 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
299 inline wxBitmapHandler()
300 { m_lType
= wxBITMAP_TYPE_INVALID
; }
302 inline wxBitmapHandler( const wxString
& rName
303 ,const wxString
& rExt
306 : wxGDIImageHandler( rName
312 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
313 // old class which worked only with bitmaps
314 virtual bool Create( wxBitmap
* pBitmap
321 virtual bool LoadFile( wxBitmap
* pBitmap
322 ,const wxString
& rName
328 virtual bool SaveFile( wxBitmap
* pBitmap
329 ,const wxString
& rName
331 ,const wxPalette
* pPalette
= NULL
334 virtual bool Create( wxGDIImage
* pImage
341 virtual bool Load( wxGDIImage
* pImage
342 ,const wxString
& rName
348 virtual bool Save( wxGDIImage
* pImage
349 ,const wxString
& rName
353 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
354 }; // end of CLASS wxBitmapHandler