1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/bitmap.h
3 // Purpose: wxBitmap class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "bitmap.h"
19 #include "wx/msw/gdiimage.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
23 class WXDLLEXPORT wxDC
;
24 class WXDLLEXPORT wxControl
;
25 class WXDLLEXPORT wxBitmap
;
26 class WXDLLEXPORT wxBitmapHandler
;
27 class WXDLLEXPORT wxBitmapRefData
;
28 class WXDLLEXPORT wxIcon
;
29 class WXDLLEXPORT wxMask
;
30 class WXDLLEXPORT wxCursor
;
31 class WXDLLEXPORT wxControl
;
32 class WXDLLEXPORT wxImage
;
33 class WXDLLEXPORT wxPalette
;
35 // ----------------------------------------------------------------------------
36 // wxBitmap: a mono or colour bitmap
37 // ----------------------------------------------------------------------------
39 class WXDLLEXPORT wxBitmap
: public wxGDIImage
42 // default ctor creates an invalid bitmap, you must Create() it later
43 wxBitmap() { Init(); }
46 wxBitmap(const wxBitmap
& bitmap
) { Init(); Ref(bitmap
); }
48 // Initialize with raw data
49 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
51 // Initialize with XPM data
52 wxBitmap(const char **data
) { CreateFromXpm(data
); }
53 wxBitmap(char **data
) { CreateFromXpm((const char **)data
); }
55 // Load a file or resource
56 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
58 // New constructor for generalised creation from data
59 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
61 // If depth is omitted, will create a bitmap compatible with the display
62 wxBitmap(int width
, int height
, int depth
= -1);
65 // Convert from wxImage:
66 wxBitmap(const wxImage
& image
, int depth
= -1)
67 { (void)CreateFromImage(image
, depth
); }
70 // we must have this, otherwise icons are silently copied into bitmaps using
71 // the copy ctor but the resulting bitmap is invalid!
72 wxBitmap(const wxIcon
& icon
) { Init(); CopyFromIcon(icon
); }
74 wxBitmap
& operator=(const wxBitmap
& bitmap
)
76 if ( m_refData
!= bitmap
.m_refData
)
81 wxBitmap
& operator=(const wxIcon
& icon
)
83 (void)CopyFromIcon(icon
);
88 wxBitmap
& operator=(const wxCursor
& cursor
)
90 (void)CopyFromCursor(cursor
);
98 wxImage
ConvertToImage() const;
101 // get the given part of bitmap
102 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
104 // copies the contents and mask of the given (colour) icon to the bitmap
105 bool CopyFromIcon(const wxIcon
& icon
);
107 // copies the contents and mask of the given cursor to the bitmap
108 bool CopyFromCursor(const wxCursor
& cursor
);
110 virtual bool Create(int width
, int height
, int depth
= -1);
111 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
112 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
113 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
115 wxBitmapRefData
*GetBitmapData() const
116 { return (wxBitmapRefData
*)m_refData
; }
119 wxPalette
* GetPalette() const;
120 void SetPalette(const wxPalette
& palette
);
121 #endif // wxUSE_PALETTE
123 wxMask
*GetMask() const;
124 void SetMask(wxMask
*mask
);
126 bool operator==(const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
127 bool operator!=(const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
129 // this function is internal and shouldn't be used, it risks to disappear
130 bool HasAlpha() const;
132 #if WXWIN_COMPATIBILITY_2_4
133 // these functions do nothing and are only there for backwards
135 wxDEPRECATED( int GetQuality() const );
136 wxDEPRECATED( void SetQuality(int quality
) );
137 #endif // WXWIN_COMPATIBILITY_2_4
139 #if WXWIN_COMPATIBILITY_2
140 void SetOk(bool isOk
);
141 #endif // WXWIN_COMPATIBILITY_2
144 #if WXWIN_COMPATIBILITY
145 wxPalette
*GetColourMap() const { return GetPalette(); }
146 void SetColourMap(wxPalette
*cmap
) { SetPalette(*cmap
); };
147 #endif // WXWIN_COMPATIBILITY
148 #endif // wxUSE_PALETTE
152 void SetHBITMAP(WXHBITMAP bmp
) { SetHandle((WXHANDLE
)bmp
); }
153 WXHBITMAP
GetHBITMAP() const { return (WXHBITMAP
)GetHandle(); }
156 void SetSelectedInto(wxDC
*dc
);
157 wxDC
*GetSelectedInto() const;
158 #endif // __WXDEBUG__
160 // Creates a bitmap that matches the device context's depth, from an
161 // arbitray bitmap. At present, the original bitmap must have an associated
162 // palette. (TODO: use a default palette if no palette exists.) This
163 // function is necessary for you to Blit an arbitrary bitmap (which may
164 // have the wrong depth). wxDC::SelectObject will compare the depth of the
165 // bitmap with the DC's depth, and create a new bitmap if the depths
166 // differ. Eventually we should perhaps make this a public API function so
167 // that an app can efficiently produce bitmaps of the correct depth. The
168 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
169 // to a DC, but this is too Windows-specific, hence this solution of
170 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
171 // <frederic.villeneuve@natinst.com>
172 wxBitmap
GetBitmapForDC(wxDC
& dc
) const;
175 // common part of all ctors
178 virtual wxGDIImageRefData
*CreateData() const;
180 // creates the bitmap from XPM data, supposed to be called from ctor
181 bool CreateFromXpm(const char **bits
);
184 // creates the bitmap from wxImage, supposed to be called from ctor
185 bool CreateFromImage(const wxImage
& image
, int depth
);
186 #endif // wxUSE_IMAGE
188 #if wxUSE_DIB_FOR_BITMAP
189 void *CreateDIB(int width
, int height
, int depth
);
191 void CopyDIBLine(void* src
, void* dest
, int count
) const;
192 #endif // wxUSE_DIB_FOR_BITMAP
196 // common part of CopyFromIcon/CopyFromCursor for Win32
197 bool CopyFromIconOrCursor(const wxGDIImage
& icon
);
200 DECLARE_DYNAMIC_CLASS(wxBitmap
)
203 // ----------------------------------------------------------------------------
204 // wxMask: a mono bitmap used for drawing bitmaps transparently.
205 // ----------------------------------------------------------------------------
207 class WXDLLEXPORT wxMask
: public wxObject
212 // Construct a mask from a bitmap and a colour indicating the transparent
214 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
216 // Construct a mask from a bitmap and a palette index indicating the
218 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
220 // Construct a mask from a mono bitmap (copies the bitmap).
221 wxMask(const wxBitmap
& bitmap
);
223 // construct a mask from the givne bitmap handle
224 wxMask(WXHBITMAP hbmp
) { m_maskBitmap
= hbmp
; }
228 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
229 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
230 bool Create(const wxBitmap
& bitmap
);
233 WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
234 void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
237 WXHBITMAP m_maskBitmap
;
239 DECLARE_DYNAMIC_CLASS(wxMask
)
242 // ----------------------------------------------------------------------------
243 // wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
244 // ----------------------------------------------------------------------------
246 class WXDLLEXPORT wxBitmapHandler
: public wxGDIImageHandler
249 wxBitmapHandler() { m_type
= wxBITMAP_TYPE_INVALID
; }
250 wxBitmapHandler(const wxString
& name
, const wxString
& ext
, long type
)
251 : wxGDIImageHandler(name
, ext
, type
)
255 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
256 // old class which worked only with bitmaps
257 virtual bool Create(wxBitmap
*bitmap
,
260 int width
, int height
, int depth
= 1);
261 virtual bool LoadFile(wxBitmap
*bitmap
,
262 const wxString
& name
,
264 int desiredWidth
, int desiredHeight
);
265 virtual bool SaveFile(wxBitmap
*bitmap
,
266 const wxString
& name
,
268 const wxPalette
*palette
= NULL
);
270 virtual bool Create(wxGDIImage
*image
,
273 int width
, int height
, int depth
= 1);
274 virtual bool Load(wxGDIImage
*image
,
275 const wxString
& name
,
277 int desiredWidth
, int desiredHeight
);
278 virtual bool Save(wxGDIImage
*image
,
279 const wxString
& name
,
283 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)