1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "bitmap.h"
19 #include "wx/palette.h"
22 class WXDLLEXPORT wxDC
;
23 class WXDLLEXPORT wxControl
;
24 class WXDLLEXPORT wxBitmap
;
25 class WXDLLEXPORT wxBitmapHandler
;
26 class WXDLLEXPORT wxIcon
;
27 class WXDLLEXPORT wxCursor
;
28 class WXDLLEXPORT wxImage
;
30 // A mask is a mono bitmap used for drawing bitmaps
32 class WXDLLEXPORT wxMask
: public wxObject
34 DECLARE_DYNAMIC_CLASS(wxMask
)
39 // Construct a mask from a bitmap and a colour indicating
40 // the transparent area
41 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
43 // Construct a mask from a bitmap and a palette index indicating
44 // the transparent area
45 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
47 // Construct a mask from a mono bitmap (copies the bitmap).
48 wxMask(const wxBitmap
& bitmap
);
52 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
53 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
54 bool Create(const wxBitmap
& bitmap
);
57 bool PointMasked(int x
, int y
);
58 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
59 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
61 WXHBITMAP m_maskBitmap
;
64 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
66 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
68 friend class WXDLLEXPORT wxBitmap
;
69 friend class WXDLLEXPORT wxIcon
;
70 friend class WXDLLEXPORT wxCursor
;
81 wxPalette m_bitmapPalette
;
88 wxMask
* m_bitmapMask
; // Optional mask
91 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
93 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
95 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
97 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
99 virtual ~wxBitmapHandler() { }
102 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
103 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
104 int desiredWidth
, int desiredHeight
);
105 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
107 inline void SetName(const wxString
& name
) { m_name
= name
; }
108 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
109 inline void SetType(long type
) { m_type
= type
; }
110 inline wxString
GetName() const { return m_name
; }
111 inline wxString
GetExtension() const { return m_extension
; }
112 inline long GetType() const { return m_type
; }
115 wxString m_extension
;
119 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
121 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
123 DECLARE_DYNAMIC_CLASS(wxBitmap
)
125 friend class WXDLLEXPORT wxBitmapHandler
;
128 wxBitmap(); // Platform-specific
131 inline wxBitmap(const wxBitmap
& bitmap
)
134 // Initialize with raw data.
135 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
137 // Initialize with XPM data
138 bool CreateFromXpm(const char **bits
);
139 wxBitmap(const char **bits
);
140 wxBitmap(char **bits
);
142 // Load a file or resource
143 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
145 // Constructor for generalised creation from data
146 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
148 // If depth is omitted, will create a bitmap compatible with the display
149 wxBitmap(int width
, int height
, int depth
= -1);
151 // Convert from wxImage:
152 wxBitmap(const wxImage
& image
, int depth
= -1);
156 wxImage
ConvertToImage() const;
158 // get the given part of bitmap
159 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
161 virtual bool Create(int width
, int height
, int depth
= -1);
162 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
163 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
164 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
166 // copies the contents and mask of the given (colour) icon to the bitmap
167 virtual bool CopyFromIcon(const wxIcon
& icon
);
170 int GetWidth() const;
171 int GetHeight() const;
172 int GetDepth() const;
173 int GetQuality() const;
174 void SetWidth(int w
);
175 void SetHeight(int h
);
176 void SetDepth(int d
);
177 void SetQuality(int q
);
178 void SetOk(bool isOk
);
180 wxPalette
* GetPalette() const;
181 void SetPalette(const wxPalette
& palette
);
183 wxMask
*GetMask() const;
184 void SetMask(wxMask
*mask
) ;
186 int GetBitmapType() const;
188 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
189 inline bool operator == (const wxBitmap
& bitmap
) { return m_refData
== bitmap
.m_refData
; }
190 inline bool operator != (const wxBitmap
& bitmap
) { return m_refData
!= bitmap
.m_refData
; }
192 static void InitStandardHandlers();
195 // TODO: Implementation
197 void SetHBITMAP(WXHBITMAP bmp
);
198 WXHBITMAP
GetHBITMAP() const;
199 void SetHICON(WXHICON ico
);
200 inline WXHICON
GetHICON() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hIcon
: 0); }
202 WXHMETAFILE
GetPict() const;
204 bool FreeResource(bool force
= FALSE
);