1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
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 bitmap used for drawing bitmaps
31 // it can be a monochrome bitmap or a multi-bit bitmap which transfers to alpha channels
33 class WXDLLEXPORT wxMask
: public wxObject
35 DECLARE_DYNAMIC_CLASS(wxMask
)
36 DECLARE_NO_COPY_CLASS(wxMask
)
41 // Construct a mask from a bitmap and a colour indicating
42 // the transparent area
43 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
45 // Construct a mask from a bitmap and a palette index indicating
46 // the transparent area
47 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
49 // Construct a mask from a mono bitmap (copies the bitmap).
50 wxMask(const wxBitmap
& bitmap
);
54 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
55 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
56 bool Create(const wxBitmap
& bitmap
);
59 bool PointMasked(int x
, int y
);
60 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
61 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
62 int GetDepth() const { return m_depth
; }
63 void SetDepth( int depth
) { m_depth
= depth
; }
65 WXHBITMAP m_maskBitmap
;
69 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
71 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
73 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
75 friend class WXDLLEXPORT wxBitmap
;
76 friend class WXDLLEXPORT wxIcon
;
77 friend class WXDLLEXPORT wxCursor
;
88 wxPalette m_bitmapPalette
;
95 wxMask
* m_bitmapMask
; // Optional mask
98 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
100 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
102 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
104 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
105 virtual ~wxBitmapHandler();
107 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
108 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
109 int desiredWidth
, int desiredHeight
);
110 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
112 void SetName(const wxString
& name
) { m_name
= name
; }
113 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
114 void SetType(long type
) { m_type
= type
; }
115 wxString
GetName() const { return m_name
; }
116 wxString
GetExtension() const { return m_extension
; }
117 long GetType() const { return m_type
; }
121 wxString m_extension
;
125 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
127 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
129 DECLARE_DYNAMIC_CLASS(wxBitmap
)
131 friend class WXDLLEXPORT wxBitmapHandler
;
134 wxBitmap(); // Platform-specific
137 wxBitmap(const wxBitmap
& bitmap
)
141 // Initialize with raw data.
142 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
144 // Initialize with XPM data
145 bool CreateFromXpm(const char **bits
);
146 wxBitmap(const char **bits
);
147 wxBitmap(char **bits
);
149 // Load a file or resource
150 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
152 // Constructor for generalised creation from data
153 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
155 // If depth is omitted, will create a bitmap compatible with the display
156 wxBitmap(int width
, int height
, int depth
= -1);
158 // Convert from wxImage:
159 wxBitmap(const wxImage
& image
, int depth
= -1);
163 wxImage
ConvertToImage() const;
165 // get the given part of bitmap
166 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
168 virtual bool Create(int width
, int height
, int depth
= -1);
169 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
170 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
171 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
173 // copies the contents and mask of the given (colour) icon to the bitmap
174 virtual bool CopyFromIcon(const wxIcon
& icon
);
177 int GetWidth() const;
178 int GetHeight() const;
179 int GetDepth() const;
180 int GetQuality() const;
181 void SetWidth(int w
);
182 void SetHeight(int h
);
183 void SetDepth(int d
);
184 void SetQuality(int q
);
185 void SetOk(bool isOk
);
187 wxPalette
* GetPalette() const;
188 void SetPalette(const wxPalette
& palette
);
190 wxMask
*GetMask() const;
191 void SetMask(wxMask
*mask
) ;
193 int GetBitmapType() const;
195 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
196 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
197 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
199 static void InitStandardHandlers();
201 WXHBITMAP
GetHBITMAP() const;
202 inline WXHICON
GetHICON() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hIcon
: 0); }
203 WXHMETAFILE
GetPict(bool *created
= NULL
) const;
205 void SetHBITMAP(WXHBITMAP bmp
);
206 void SetHICON(WXHICON ico
);
207 void SetPict( WXHMETAFILE pict
) ;
209 bool FreeResource(bool force
= FALSE
);