1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "bitmap.h"
19 #include "wx/palette.h"
22 class WXDLLEXPORT wxBitmap
;
23 class WXDLLEXPORT wxBitmapHandler
;
24 class WXDLLEXPORT wxIcon
;
25 class WXDLLEXPORT wxCursor
;
26 class WXDLLEXPORT wxImage
;
28 // A mask is a mono bitmap used for drawing bitmaps
30 class WXDLLEXPORT wxMask
: public wxObject
32 DECLARE_DYNAMIC_CLASS(wxMask
)
33 DECLARE_NO_COPY_CLASS(wxMask
)
38 // Construct a mask from a bitmap and a colour indicating
39 // the transparent area
40 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
42 // Construct a mask from a bitmap and a palette index indicating
43 // the transparent area
44 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
46 // Construct a mask from a mono bitmap (copies the bitmap).
47 wxMask(const wxBitmap
& bitmap
);
51 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
52 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
53 bool Create(const wxBitmap
& bitmap
);
56 // inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
57 // inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
59 // WXHBITMAP m_maskBitmap;
62 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
64 DECLARE_NO_COPY_CLASS(wxBitmapRefData
)
66 friend class WXDLLEXPORT wxBitmap
;
67 friend class WXDLLEXPORT wxIcon
;
68 friend class WXDLLEXPORT wxCursor
;
79 wxPalette m_bitmapPalette
;
82 // TOTO: platofmr specific hBitmap
83 // WXHBITMAP m_hBitmap;
84 wxMask
* m_bitmapMask
; // Optional mask
87 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
89 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
91 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
93 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { }
94 virtual ~wxBitmapHandler();
96 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
97 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
98 int desiredWidth
, int desiredHeight
);
99 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
101 void SetName(const wxString
& name
) { m_name
= name
; }
102 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
103 void SetType(long type
) { m_type
= type
; }
104 wxString
GetName() const { return m_name
; }
105 wxString
GetExtension() const { return m_extension
; }
106 long GetType() const { return m_type
; }
110 wxString m_extension
;
114 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
116 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
118 DECLARE_DYNAMIC_CLASS(wxBitmap
)
120 friend class WXDLLEXPORT wxBitmapHandler
;
123 wxBitmap(); // Platform-specific
126 wxBitmap(const wxBitmap
& bitmap
)
130 // Initialize with raw data.
131 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
133 // Initialize with XPM data
134 bool CreateFromXpm(const char **bits
);
135 wxBitmap(const char **bits
) { CreateFromXpm(bits
); }
136 wxBitmap(char **bits
);
138 // Load a file or resource
139 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
141 // Constructor for generalised creation from data
142 wxBitmap(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
144 // If depth is omitted, will create a bitmap compatible with the display
145 wxBitmap(int width
, int height
, int depth
= -1);
147 // Convert from wxImage:
148 wxBitmap(const wxImage
& image
, int depth
= -1);
152 wxImage
ConvertToImage() const;
154 // get the given part of bitmap
155 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
157 virtual bool Create(int width
, int height
, int depth
= -1);
158 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
159 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
160 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
162 // copies the contents and mask of the given (colour) icon to the bitmap
163 virtual bool CopyFromIcon(const wxIcon
& icon
);
166 int GetWidth() const;
167 int GetHeight() const;
168 int GetDepth() const;
169 int GetQuality() const;
170 void SetWidth(int w
);
171 void SetHeight(int h
);
172 void SetDepth(int d
);
173 void SetQuality(int q
);
174 void SetOk(bool isOk
);
176 wxPalette
* GetPalette() const;
177 void SetPalette(const wxPalette
& palette
);
179 wxMask
*GetMask() const;
180 void SetMask(wxMask
*mask
) ;
182 int GetBitmapType() const;
184 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
185 inline bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
186 inline bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
188 static void InitStandardHandlers();
191 // TODO: Implementation
193 // void SetHBITMAP(WXHBITMAP bmp);
194 // WXHBITMAP GetHBITMAP() const;
196 // WXHMETAFILE GetPict() const;
198 bool FreeResource(bool force
= FALSE
);