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
;
59 // Optional mask for transparent drawing
61 wxMask
* m_pBitmapMask
;
62 }; // end of CLASS wxBitmapRefData
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(const char** ppData
);
87 wxBitmap(char** ppData
);
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 // get the given part of bitmap
136 wxBitmap
GetSubBitmap(const wxRect
& rRect
) const;
138 // copies the contents and mask of the given (colour) icon to the bitmap
139 bool CopyFromIcon(const wxIcon
& rIcon
);
141 // copies the contents and mask of the given cursor to the bitmap
142 bool CopyFromCursor(const wxCursor
& rCursor
);
144 virtual bool Create( int nWidth
148 virtual bool Create( void* pData
154 virtual bool LoadFile( const wxString
& rName
155 ,long lType
= wxBITMAP_TYPE_BMP_RESOURCE
157 virtual bool SaveFile( const wxString
& rName
159 ,const wxPalette
* pCmap
= NULL
162 inline wxBitmapRefData
* GetBitmapData() const
163 { return (wxBitmapRefData
*)m_refData
; }
165 inline int GetQuality() const
166 { return (GetBitmapData() ? GetBitmapData()->m_nQuality
: 0); }
168 void SetQuality(int nQ
);
170 wxPalette
* GetPalette() const
171 { return (GetBitmapData() ? (& GetBitmapData()->m_vBitmapPalette
) : (wxPalette
*) NULL
); }
173 void SetPalette(const wxPalette
& rPalette
);
175 inline wxMask
* GetMask() const
176 { return (GetBitmapData() ? GetBitmapData()->m_pBitmapMask
: (wxMask
*) NULL
); }
178 void SetMask(wxMask
* pMask
) ;
180 inline bool operator==(const wxBitmap
& rBitmap
)
181 { return m_refData
== rBitmap
.m_refData
; }
183 inline bool operator!=(const wxBitmap
& rBitmap
)
184 { return m_refData
!= rBitmap
.m_refData
; }
186 #if WXWIN_COMPATIBILITY_2
187 void SetOk(bool bIsOk
);
188 #endif // WXWIN_COMPATIBILITY_2
190 #if WXWIN_COMPATIBILITY
191 inline wxPalette
* GetColourMap() const
192 { return GetPalette(); }
194 inline void SetColourMap(wxPalette
* pCmap
)
195 { SetPalette(*pCmap
); };
197 #endif // WXWIN_COMPATIBILITY
201 inline void SetHBITMAP(WXHBITMAP hBmp
)
202 { SetHandle((WXHANDLE
)hBmp
); }
204 inline WXHBITMAP
GetHBITMAP() const
205 { return (WXHBITMAP
)GetHandle(); }
207 inline void SetSelectedInto(wxDC
* pDc
)
208 { if (GetBitmapData()) GetBitmapData()->m_pSelectedInto
= pDc
; }
210 inline wxDC
* GetSelectedInto() const
211 { return (GetBitmapData() ? GetBitmapData()->m_pSelectedInto
: (wxDC
*) NULL
); }
213 // An OS/2 version that probably doesn't do anything like the msw version
214 wxBitmap
GetBitmapForDC(wxDC
& rDc
) const;
216 // inline LONG GetId() const
217 // { return (GetBitmapData() ? GetBitmapData()->m_lId : 0L); }
221 // common part of all ctors
224 inline virtual wxGDIImageRefData
* CreateData() const
225 { return new wxBitmapRefData
; }
227 // creates the bitmap from XPM data, supposed to be called from ctor
228 bool CreateFromXpm(const char **bits
);
231 bool CopyFromIconOrCursor(const wxGDIImage
& rIcon
);
233 DECLARE_DYNAMIC_CLASS(wxBitmap
)
234 }; // end of 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
)
283 }; // end of 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
321 virtual bool SaveFile( wxBitmap
* pBitmap
322 ,const wxString
& rName
324 ,const wxPalette
* pPalette
= NULL
327 virtual bool Create( wxGDIImage
* pImage
334 virtual bool Load( wxGDIImage
* pImage
335 ,const wxString
& rName
341 virtual bool Save( wxGDIImage
* pImage
342 ,const wxString
& rName
346 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
347 }; // end of CLASS wxBitmapHandler