1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/palmos/gdiimage.h"
16 #include "wx/gdicmn.h"
17 #include "wx/palette.h"
19 class WXDLLEXPORT wxBitmap
;
20 class WXDLLEXPORT wxBitmapHandler
;
21 class WXDLLEXPORT wxBitmapRefData
;
22 class WXDLLEXPORT wxControl
;
23 class WXDLLEXPORT wxCursor
;
24 class WXDLLEXPORT wxDC
;
26 class WXDLLEXPORT wxDIB
;
28 class WXDLLEXPORT wxIcon
;
29 class WXDLLEXPORT wxImage
;
30 class WXDLLEXPORT wxMask
;
31 class WXDLLEXPORT wxPalette
;
32 class WXDLLEXPORT wxPixelDataBase
;
34 // ----------------------------------------------------------------------------
35 // wxBitmap: a mono or colour bitmap
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxBitmap
: public wxGDIImage
41 // default ctor creates an invalid bitmap, you must Create() it later
42 wxBitmap() { Init(); }
44 // Initialize with raw data
45 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
47 // Initialize with XPM data
48 wxBitmap(const char* const* data
);
50 // Load a file or resource
51 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
53 // New constructor for generalised creation from data
54 wxBitmap(const void* data
, long type
, int width
, int height
, int depth
= 1);
56 // Create a new, uninitialized bitmap of the given size and depth (if it
57 // is omitted, will create a bitmap compatible with the display)
59 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor
60 // taking a DC argument if you want to force using DDB in this case
61 wxBitmap(int width
, int height
, int depth
= -1);
63 // Create a bitmap compatible with the given DC
64 wxBitmap(int width
, int height
, const wxDC
& dc
);
66 #if wxUSE_IMAGE && wxUSE_WXDIB
67 // Convert from wxImage
68 wxBitmap(const wxImage
& image
, int depth
= -1)
69 { (void)CreateFromImage(image
, depth
); }
71 // Create a DDB compatible with the given DC from wxImage
72 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
73 { (void)CreateFromImage(image
, dc
); }
76 // we must have this, otherwise icons are silently copied into bitmaps using
77 // the copy ctor but the resulting bitmap is invalid!
78 wxBitmap(const wxIcon
& icon
) { Init(); CopyFromIcon(icon
); }
80 wxBitmap
& operator=(const wxIcon
& icon
)
82 (void)CopyFromIcon(icon
);
87 wxBitmap
& operator=(const wxCursor
& cursor
)
89 (void)CopyFromCursor(cursor
);
96 #if wxUSE_IMAGE && wxUSE_WXDIB
97 wxImage
ConvertToImage() const;
100 // get the given part of bitmap
101 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
103 // copies the contents and mask of the given (colour) icon to the bitmap
104 bool CopyFromIcon(const wxIcon
& icon
);
106 // copies the contents and mask of the given cursor to the bitmap
107 bool CopyFromCursor(const wxCursor
& cursor
);
110 // copies from a device independent bitmap
111 bool CopyFromDIB(const wxDIB
& dib
);
114 virtual bool Create(int width
, int height
, int depth
= -1);
115 virtual bool Create(int width
, int height
, const wxDC
& dc
);
116 virtual bool Create(const void* data
, long type
, int width
, int height
, int depth
= 1);
117 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
118 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
120 wxBitmapRefData
*GetBitmapData() const
121 { return (wxBitmapRefData
*)m_refData
; }
123 // raw bitmap access support functions
124 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
125 void UngetRawData(wxPixelDataBase
& data
);
128 wxPalette
* GetPalette() const;
129 void SetPalette(const wxPalette
& palette
);
130 #endif // wxUSE_PALETTE
132 wxMask
*GetMask() const;
133 void SetMask(wxMask
*mask
);
135 bool operator==(const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
136 bool operator!=(const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
138 // these functions are internal and shouldn't be used, they risk to
139 // disappear in the future
140 bool HasAlpha() const;
143 // implementation only from now on
144 // -------------------------------
147 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
148 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
151 void SetSelectedInto(wxDC
*dc
);
152 wxDC
*GetSelectedInto() const;
153 #endif // __WXDEBUG__
156 // common part of all ctors
159 virtual wxGDIImageRefData
*CreateData() const;
161 // creates an uninitialized bitmap, called from Create()s above
162 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
164 #if wxUSE_IMAGE && wxUSE_WXDIB
165 // creates the bitmap from wxImage, supposed to be called from ctor
166 bool CreateFromImage(const wxImage
& image
, int depth
);
168 // creates a DDB from wxImage, supposed to be called from ctor
169 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
171 // common part of the 2 methods above (hdc may be 0)
172 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
173 #endif // wxUSE_IMAGE
176 DECLARE_DYNAMIC_CLASS(wxBitmap
)
179 // ----------------------------------------------------------------------------
180 // wxMask: a mono bitmap used for drawing bitmaps transparently.
181 // ----------------------------------------------------------------------------
183 class WXDLLEXPORT wxMask
: public wxObject
188 // Construct a mask from a bitmap and a colour indicating the transparent
190 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
192 // Construct a mask from a bitmap and a palette index indicating the
194 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
196 // Construct a mask from a mono bitmap (copies the bitmap).
197 wxMask(const wxBitmap
& bitmap
);
199 // construct a mask from the givne bitmap handle
200 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
204 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
205 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
206 bool Create(const wxBitmap
& bitmap
);
209 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
210 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
213 WXHBITMAP m_maskBitmap
;
215 DECLARE_DYNAMIC_CLASS(wxMask
)
218 // ----------------------------------------------------------------------------
219 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
220 // ----------------------------------------------------------------------------
222 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
225 wxBitmapHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
226 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
227 : wxGDIImageHandler(name
, ext
, type
)
231 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
232 // old class which worked only with bitmaps
233 virtual bool Create(wxBitmap
*bitmap
,
236 int width
, int height
, int depth
= 1);
237 virtual bool LoadFile(wxBitmap
*bitmap
,
238 const wxString
& name
,
240 int desiredWidth
, int desiredHeight
);
241 virtual bool SaveFile(wxBitmap
*bitmap
,
242 const wxString
& name
,
244 const wxPalette
*palette
= NULL
);
246 virtual bool Create(wxGDIImage
*image
,
249 int width
, int height
, int depth
= 1);
250 virtual bool Load(wxGDIImage
*image
,
251 const wxString
& name
,
253 int desiredWidth
, int desiredHeight
);
254 virtual bool Save(wxGDIImage
*image
,
255 const wxString
& name
,
259 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)