1 /////////////////////////////////////////////////////////////////////////////
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/gdiobj.h"
20 #include "wx/gdicmn.h"
21 #include "wx/palette.h"
24 class WXDLLEXPORT wxDC
;
25 class WXDLLEXPORT wxControl
;
26 class WXDLLEXPORT wxBitmap
;
27 class WXDLLEXPORT wxBitmapHandler
;
28 class WXDLLEXPORT wxIcon
;
29 class WXDLLEXPORT wxCursor
;
30 class WXDLLEXPORT wxImage
;
32 // A mask is a mono bitmap used for drawing bitmaps
34 class WXDLLEXPORT wxMask
: public wxObject
36 DECLARE_DYNAMIC_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
);
58 WXPixmap
GetPixmap() const { return m_pixmap
; }
59 void SetPixmap(WXPixmap pixmap
) { m_pixmap
= pixmap
; }
65 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
67 friend class WXDLLEXPORT wxBitmap
;
68 friend class WXDLLEXPORT wxIcon
;
69 friend class WXDLLEXPORT wxCursor
;
79 // XXX int m_numColors;
80 wxPalette m_bitmapPalette
;
83 wxMask
* m_bitmapMask
; // Optional mask
85 // Motif implementation
89 // XXX bool m_freePixmap;
91 unsigned long* m_freeColors
;
92 long m_freeColorsCount
;
96 // These 5 variables are for wxControl
97 WXPixmap m_insensPixmap
;
98 WXPixmap m_labelPixmap
;
99 WXPixmap m_armPixmap
;
103 WXImage
* m_insensImage
;
107 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
109 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
112 wxBitmapHandler() : wxBitmapHandlerBase() { }
114 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
115 int width
, int height
, int depth
= 1)
120 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
121 int desiredWidth
, int desiredHeight
)
126 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
127 int type
, const wxPalette
*palette
= NULL
)
132 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
135 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
137 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
139 DECLARE_DYNAMIC_CLASS(wxBitmap
)
141 friend class WXDLLEXPORT wxBitmapHandler
;
144 wxBitmap(); // Platform-specific
147 wxBitmap(const wxBitmap
& bitmap
)
150 // Initialize with raw XBM data
151 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
154 wxBitmap(const char **data
) { (void)CreateFromXpm(data
); }
155 wxBitmap(char **data
) { (void)CreateFromXpm((const char **)data
); }
157 // Initialize with XPM data -- deprecated
158 wxBitmap(char **data
, wxControl
* control
);
160 // Load a file or resource
161 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_XPM
);
163 // Constructor for generalised creation from data
164 wxBitmap(void *data
, wxBitmapType type
,
165 int width
, int height
, int depth
= 1);
167 // If depth is omitted, will create a bitmap compatible with the display
168 wxBitmap(int width
, int height
, int depth
= -1);
170 // Convert from wxImage:
171 wxBitmap(const wxImage
& image
, int depth
= -1) { (void)CreateFromImage(image
, depth
); }
175 virtual bool Create(int width
, int height
, int depth
= -1);
176 virtual bool Create(void *data
, wxBitmapType type
,
177 int width
, int height
, int depth
= 1);
179 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
181 virtual bool LoadFile(const wxString
& name
,
182 wxBitmapType type
= wxBITMAP_TYPE_XPM
);
183 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
184 const wxPalette
*cmap
= NULL
) const;
186 wxImage
ConvertToImage() const;
188 // copies the contents and mask of the given (colour) icon to the bitmap
189 virtual bool CopyFromIcon(const wxIcon
& icon
);
191 bool Ok() const { return (M_BITMAPDATA
&& M_BITMAPDATA
->m_ok
); }
192 int GetWidth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_width
: 0); }
193 int GetHeight() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_height
: 0); }
194 int GetDepth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_depth
: 0); }
195 // XXX int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); }
196 void SetWidth(int w
);
197 void SetHeight(int h
);
198 void SetDepth(int d
);
199 // XXX void SetQuality(int q);
200 void SetOk(bool isOk
);
202 wxPalette
* GetPalette() const { return (M_BITMAPDATA
? (& M_BITMAPDATA
->m_bitmapPalette
) : (wxPalette
*) NULL
); }
203 void SetPalette(const wxPalette
& palette
);
205 wxMask
*GetMask() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_bitmapMask
: (wxMask
*) NULL
); }
206 void SetMask(wxMask
*mask
) ;
208 wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
209 bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
210 bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
213 static void InitStandardHandlers();
215 // Motif implementation
217 WXDisplay
* GetDisplay() const { return M_BITMAPDATA
->m_display
; }
218 WXPixmap
GetPixmap() const { return (WXPixmap
) M_BITMAPDATA
->m_pixmap
; }
220 virtual WXPixmap
GetLabelPixmap(WXWidget w
) ;
221 virtual WXPixmap
GetArmPixmap(WXWidget w
) ;
222 virtual WXPixmap
GetInsensPixmap(WXWidget w
= (WXWidget
) 0) ;
224 void SetPixmapNull() { M_BITMAPDATA
->m_pixmap
= 0; }
227 bool CreateFromXpm(const char **bits
);
228 bool CreateFromImage(const wxImage
& image
, int depth
);
231 // Creates a bitmap with transparent areas drawn in
233 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, wxColour
& colour
);