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 mono bitmap used for drawing bitmaps
32 class WXDLLEXPORT wxMask
: public wxObject
34 DECLARE_DYNAMIC_CLASS(wxMask
)
35 DECLARE_NO_COPY_CLASS(wxMask
)
40 // Construct a mask from a bitmap and a colour indicating
41 // the transparent area
42 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
44 // Construct a mask from a bitmap and a palette index indicating
45 // the transparent area
46 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
48 // Construct a mask from a mono bitmap (copies the bitmap).
49 wxMask(const wxBitmap
& bitmap
);
53 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
54 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
55 bool Create(const wxBitmap
& bitmap
);
58 bool PointMasked(int x
, int y
);
59 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
60 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
62 WXHBITMAP m_maskBitmap
;
65 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
67 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
69 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
71 friend class WXDLLEXPORT wxBitmap
;
72 friend class WXDLLEXPORT wxIcon
;
73 friend class WXDLLEXPORT wxCursor
;
84 wxPalette m_bitmapPalette
;
91 wxMask
* m_bitmapMask
; // Optional mask
94 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
96 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
98 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
100 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
101 virtual ~wxBitmapHandler();
103 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
104 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
105 int desiredWidth
, int desiredHeight
);
106 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
108 void SetName(const wxString
& name
) { m_name
= name
; }
109 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
110 void SetType(long type
) { m_type
= type
; }
111 wxString
GetName() const { return m_name
; }
112 wxString
GetExtension() const { return m_extension
; }
113 long GetType() const { return m_type
; }
117 wxString m_extension
;
121 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
123 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
125 DECLARE_DYNAMIC_CLASS(wxBitmap
)
127 friend class WXDLLEXPORT wxBitmapHandler
;
130 wxBitmap(); // Platform-specific
133 wxBitmap(const wxBitmap
& bitmap
)
137 // Initialize with raw data.
138 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
140 // Initialize with XPM data
141 bool CreateFromXpm(const char **bits
);
142 wxBitmap(const char **bits
);
143 wxBitmap(char **bits
);
145 // Load a file or resource
146 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
148 // Constructor for generalised creation from data
149 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
151 // If depth is omitted, will create a bitmap compatible with the display
152 wxBitmap(int width
, int height
, int depth
= -1);
154 // Convert from wxImage:
155 wxBitmap(const wxImage
& image
, int depth
= -1);
159 wxImage
ConvertToImage() const;
161 // get the given part of bitmap
162 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
164 virtual bool Create(int width
, int height
, int depth
= -1);
165 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
166 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
167 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
169 // copies the contents and mask of the given (colour) icon to the bitmap
170 virtual bool CopyFromIcon(const wxIcon
& icon
);
173 int GetWidth() const;
174 int GetHeight() const;
175 int GetDepth() const;
176 int GetQuality() const;
177 void SetWidth(int w
);
178 void SetHeight(int h
);
179 void SetDepth(int d
);
180 void SetQuality(int q
);
181 void SetOk(bool isOk
);
183 wxPalette
* GetPalette() const;
184 void SetPalette(const wxPalette
& palette
);
186 wxMask
*GetMask() const;
187 void SetMask(wxMask
*mask
) ;
189 int GetBitmapType() const;
191 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
192 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
193 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
195 static void InitStandardHandlers();
197 WXHBITMAP
GetHBITMAP() const;
198 inline WXHICON
GetHICON() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hIcon
: 0); }
199 WXHMETAFILE
GetPict(bool *created
= NULL
) const;
201 void SetHBITMAP(WXHBITMAP bmp
);
202 void SetHICON(WXHICON ico
);
203 void SetPict( WXHMETAFILE pict
) ;
205 bool FreeResource(bool force
= FALSE
);