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 WXDLLIMPEXP_FWD_CORE wxBitmap
;
20 class WXDLLIMPEXP_FWD_CORE wxBitmapHandler
;
21 class WXDLLIMPEXP_FWD_CORE wxBitmapRefData
;
22 class WXDLLIMPEXP_FWD_CORE wxControl
;
23 class WXDLLIMPEXP_FWD_CORE wxCursor
;
24 class WXDLLIMPEXP_FWD_CORE wxDC
;
26 class WXDLLIMPEXP_FWD_CORE wxDIB
;
28 class WXDLLIMPEXP_FWD_CORE wxIcon
;
29 class WXDLLIMPEXP_FWD_CORE wxImage
;
30 class WXDLLIMPEXP_FWD_CORE wxMask
;
31 class WXDLLIMPEXP_FWD_CORE wxPalette
;
32 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase
;
34 // ----------------------------------------------------------------------------
35 // wxBitmap: a mono or colour bitmap
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE 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_DEFAULT_TYPE
);
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) { /*TODO*/ }
62 wxBitmap(const wxSize
& sz
, int depth
= -1) { /*TODO*/ }
64 // Create a bitmap compatible with the given DC
65 wxBitmap(int width
, int height
, const wxDC
& dc
);
67 #if wxUSE_IMAGE && wxUSE_WXDIB
68 // Convert from wxImage
69 wxBitmap(const wxImage
& image
, int depth
= -1)
70 { (void)CreateFromImage(image
, depth
); }
72 // Create a DDB compatible with the given DC from wxImage
73 wxBitmap(const wxImage
& image
, const wxDC
& dc
)
74 { (void)CreateFromImage(image
, dc
); }
77 // we must have this, otherwise icons are silently copied into bitmaps using
78 // the copy ctor but the resulting bitmap is invalid!
79 wxBitmap(const wxIcon
& icon
) { Init(); CopyFromIcon(icon
); }
81 wxBitmap
& operator=(const wxIcon
& icon
)
83 (void)CopyFromIcon(icon
);
88 wxBitmap
& operator=(const wxCursor
& cursor
)
90 (void)CopyFromCursor(cursor
);
95 virtual ~wxBitmap() {}
97 #if wxUSE_IMAGE && wxUSE_WXDIB
98 wxImage
ConvertToImage() const;
99 wxBitmap
ConvertToDisabled(unsigned char brightness
= 255) const;
100 #endif // wxUSE_IMAGE
102 // get the given part of bitmap
103 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
105 // copies the contents and mask of the given (colour) icon to the bitmap
106 bool CopyFromIcon(const wxIcon
& icon
);
108 // copies the contents and mask of the given cursor to the bitmap
109 bool CopyFromCursor(const wxCursor
& cursor
);
112 // copies from a device independent bitmap
113 bool CopyFromDIB(const wxDIB
& dib
);
116 virtual bool Create(int width
, int height
, int depth
= wxBITMAP_SCREEN_DEPTH
);
117 virtual bool Create(const wxSize
& sz
, int depth
= wxBITMAP_SCREEN_DEPTH
)
118 { return Create(sz
.GetWidth(), sz
.GetHeight(), depth
); }
120 virtual bool Create(int width
, int height
, const wxDC
& dc
);
121 virtual bool Create(const void* data
, long type
, int width
, int height
, int depth
= 1);
122 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_DEFAULT_TYPE
);
123 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
125 wxBitmapRefData
*GetBitmapData() const
126 { return (wxBitmapRefData
*)m_refData
; }
128 // raw bitmap access support functions
129 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
130 void UngetRawData(wxPixelDataBase
& data
);
133 wxPalette
* GetPalette() const;
134 void SetPalette(const wxPalette
& palette
);
135 #endif // wxUSE_PALETTE
137 wxMask
*GetMask() const;
138 void SetMask(wxMask
*mask
);
140 // these functions are internal and shouldn't be used, they risk to
141 // disappear in the future
142 bool HasAlpha() const;
144 // implementation only from now on
145 // -------------------------------
148 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
149 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
152 // common part of all ctors
155 virtual wxGDIImageRefData
*CreateData() const;
157 // creates an uninitialized bitmap, called from Create()s above
158 bool DoCreate(int w
, int h
, int depth
, WXHDC hdc
);
160 #if wxUSE_IMAGE && wxUSE_WXDIB
161 // creates the bitmap from wxImage, supposed to be called from ctor
162 bool CreateFromImage(const wxImage
& image
, int depth
);
164 // creates a DDB from wxImage, supposed to be called from ctor
165 bool CreateFromImage(const wxImage
& image
, const wxDC
& dc
);
167 // common part of the 2 methods above (hdc may be 0)
168 bool CreateFromImage(const wxImage
& image
, int depth
, WXHDC hdc
);
169 #endif // wxUSE_IMAGE
172 DECLARE_DYNAMIC_CLASS(wxBitmap
)
175 // ----------------------------------------------------------------------------
176 // wxMask: a mono bitmap used for drawing bitmaps transparently.
177 // ----------------------------------------------------------------------------
179 class WXDLLIMPEXP_CORE wxMask
: public wxObject
184 // Construct a mask from a bitmap and a colour indicating the transparent
186 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
188 // Construct a mask from a bitmap and a palette index indicating the
190 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
192 // Construct a mask from a mono bitmap (copies the bitmap).
193 wxMask(const wxBitmap
& bitmap
);
195 // construct a mask from the givne bitmap handle
196 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
200 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
201 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
202 bool Create(const wxBitmap
& bitmap
);
205 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
206 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
209 WXHBITMAP m_maskBitmap
;
211 DECLARE_DYNAMIC_CLASS(wxMask
)
214 // ----------------------------------------------------------------------------
215 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
216 // ----------------------------------------------------------------------------
218 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxGDIImageHandler
221 wxBitmapHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
222 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
223 : wxGDIImageHandler(name
, ext
, type
)
227 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
228 // old class which worked only with bitmaps
229 virtual bool Create(wxBitmap
*bitmap
,
232 int width
, int height
, int depth
= 1);
233 virtual bool LoadFile(wxBitmap
*bitmap
,
234 const wxString
& name
,
236 int desiredWidth
, int desiredHeight
);
237 virtual bool SaveFile(wxBitmap
*bitmap
,
238 const wxString
& name
,
240 const wxPalette
*palette
= NULL
);
242 virtual bool Create(wxGDIImage
*image
,
245 int width
, int height
, int depth
= 1);
246 virtual bool Load(wxGDIImage
*image
,
247 const wxString
& name
,
249 int desiredWidth
, int desiredHeight
);
250 virtual bool Save(wxGDIImage
*image
,
251 const wxString
& name
,
255 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)