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
;
80 wxPalette m_bitmapPalette
;
83 wxMask
* m_bitmapMask
; // Optional mask
85 // Motif implementation
90 unsigned long* m_freeColors
;
91 long m_freeColorsCount
;
93 // These 5 variables are for wxControl
94 WXPixmap m_insensPixmap
;
95 WXPixmap m_labelPixmap
;
96 WXPixmap m_armPixmap
;
98 WXImage
* m_insensImage
;
101 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
103 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
106 wxBitmapHandler() : wxBitmapHandlerBase() { }
108 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
109 int width
, int height
, int depth
= 1)
114 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
115 int desiredWidth
, int desiredHeight
)
120 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
121 int type
, const wxPalette
*palette
= NULL
)
126 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
129 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
131 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
133 DECLARE_DYNAMIC_CLASS(wxBitmap
)
135 friend class WXDLLEXPORT wxBitmapHandler
;
138 wxBitmap(); // Platform-specific
141 wxBitmap(const wxBitmap
& bitmap
)
144 // Initialize with raw XBM data
145 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
148 wxBitmap(const char **data
) { (void)CreateFromXpm(data
); }
149 wxBitmap(char **data
) { (void)CreateFromXpm((const char **)data
); }
151 // Initialize with XPM data -- deprecated
152 wxBitmap(char **data
, wxControl
* control
);
154 // Load a file or resource
155 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_XPM
);
157 // Constructor for generalised creation from data
158 wxBitmap(void *data
, wxBitmapType type
,
159 int width
, int height
, int depth
= 1);
161 // If depth is omitted, will create a bitmap compatible with the display
162 wxBitmap(int width
, int height
, int depth
= -1);
164 // Convert from wxImage:
165 wxBitmap(const wxImage
& image
, int depth
= -1) { (void)CreateFromImage(image
, depth
); }
169 virtual bool Create(int width
, int height
, int depth
= -1);
170 virtual bool Create(void *data
, wxBitmapType type
,
171 int width
, int height
, int depth
= 1);
173 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
175 virtual bool LoadFile(const wxString
& name
,
176 wxBitmapType type
= wxBITMAP_TYPE_XPM
);
177 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
,
178 const wxPalette
*cmap
= NULL
) const;
180 wxImage
ConvertToImage() const;
182 // copies the contents and mask of the given (colour) icon to the bitmap
183 virtual bool CopyFromIcon(const wxIcon
& icon
);
185 bool Ok() const { return (M_BITMAPDATA
&& M_BITMAPDATA
->m_ok
); }
186 int GetWidth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_width
: 0); }
187 int GetHeight() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_height
: 0); }
188 int GetDepth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_depth
: 0); }
189 int GetQuality() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_quality
: 0); }
190 void SetWidth(int w
);
191 void SetHeight(int h
);
192 void SetDepth(int d
);
193 void SetQuality(int q
);
194 void SetOk(bool isOk
);
196 wxPalette
* GetPalette() const { return (M_BITMAPDATA
? (& M_BITMAPDATA
->m_bitmapPalette
) : (wxPalette
*) NULL
); }
197 void SetPalette(const wxPalette
& palette
);
199 wxMask
*GetMask() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_bitmapMask
: (wxMask
*) NULL
); }
200 void SetMask(wxMask
*mask
) ;
202 wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
203 bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
204 bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
207 static void InitStandardHandlers();
209 // Motif implementation
211 WXDisplay
* GetDisplay() const { return M_BITMAPDATA
->m_display
; }
212 WXPixmap
GetPixmap() const { return (WXPixmap
) M_BITMAPDATA
->m_pixmap
; }
213 virtual WXPixmap
GetLabelPixmap(WXWidget w
) ;
214 virtual WXPixmap
GetArmPixmap(WXWidget w
) ;
215 virtual WXPixmap
GetInsensPixmap(WXWidget w
= (WXWidget
) 0) ;
216 void SetPixmapNull() { M_BITMAPDATA
->m_pixmap
= 0; }
219 bool CreateFromXpm(const char **bits
);
220 bool CreateFromImage(const wxImage
& image
, int depth
);
223 // Creates a bitmap with transparent areas drawn in
225 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, wxColour
& colour
);