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 wxObject
105 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
107 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
109 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
110 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
111 int desiredWidth
, int desiredHeight
);
112 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
114 void SetName(const wxString
& name
) { m_name
= name
; }
115 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
116 void SetType(long type
) { m_type
= type
; }
117 wxString
GetName() const { return m_name
; }
118 wxString
GetExtension() const { return m_extension
; }
119 long GetType() const { return m_type
; }
122 wxString m_extension
;
126 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
128 class WXDLLEXPORT wxBitmap
: public wxGDIObject
130 DECLARE_DYNAMIC_CLASS(wxBitmap
)
132 friend class WXDLLEXPORT wxBitmapHandler
;
135 wxBitmap(); // Platform-specific
138 wxBitmap(const wxBitmap
& bitmap
)
141 // Initialize with raw XBM data
142 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
145 wxBitmap(const char **data
) { (void)CreateFromXpm(data
); }
146 wxBitmap(char **data
) { (void)CreateFromXpm((const char **)data
); }
148 // Initialize with XPM data -- deprecated
149 wxBitmap(char **data
, wxControl
* control
);
151 // Load a file or resource
152 wxBitmap(const wxString
& name
, int type
= wxBITMAP_TYPE_XPM
);
154 // Constructor for generalised creation from data
155 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
157 // If depth is omitted, will create a bitmap compatible with the display
158 wxBitmap(int width
, int height
, int depth
= -1);
160 // Convert from wxImage:
161 wxBitmap(const wxImage
& image
, int depth
= -1) { (void)CreateFromImage(image
, depth
); }
165 virtual bool Create(int width
, int height
, int depth
= -1);
166 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
168 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
170 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_XPM
);
171 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
173 wxImage
ConvertToImage() const;
175 // copies the contents and mask of the given (colour) icon to the bitmap
176 virtual bool CopyFromIcon(const wxIcon
& icon
);
178 bool Ok() const { return (M_BITMAPDATA
&& M_BITMAPDATA
->m_ok
); }
179 int GetWidth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_width
: 0); }
180 int GetHeight() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_height
: 0); }
181 int GetDepth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_depth
: 0); }
182 int GetQuality() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_quality
: 0); }
183 void SetWidth(int w
);
184 void SetHeight(int h
);
185 void SetDepth(int d
);
186 void SetQuality(int q
);
187 void SetOk(bool isOk
);
189 wxPalette
* GetPalette() const { return (M_BITMAPDATA
? (& M_BITMAPDATA
->m_bitmapPalette
) : (wxPalette
*) NULL
); }
190 void SetPalette(const wxPalette
& palette
);
192 wxMask
*GetMask() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_bitmapMask
: (wxMask
*) NULL
); }
193 void SetMask(wxMask
*mask
) ;
195 wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
196 bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
197 bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
200 static wxList
& GetHandlers() { return sm_handlers
; }
201 static void AddHandler(wxBitmapHandler
*handler
);
202 static void InsertHandler(wxBitmapHandler
*handler
);
203 static bool RemoveHandler(const wxString
& name
);
204 static wxBitmapHandler
*FindHandler(const wxString
& name
);
205 static wxBitmapHandler
*FindHandler(const wxString
& extension
, long bitmapType
);
206 static wxBitmapHandler
*FindHandler(long bitmapType
);
208 static void InitStandardHandlers();
209 static void CleanUpHandlers();
211 // Motif implementation
213 WXDisplay
* GetDisplay() const { return M_BITMAPDATA
->m_display
; }
214 WXPixmap
GetPixmap() const { return (WXPixmap
) M_BITMAPDATA
->m_pixmap
; }
215 virtual WXPixmap
GetLabelPixmap(WXWidget w
) ;
216 virtual WXPixmap
GetArmPixmap(WXWidget w
) ;
217 virtual WXPixmap
GetInsensPixmap(WXWidget w
= (WXWidget
) 0) ;
218 void SetPixmapNull() { M_BITMAPDATA
->m_pixmap
= 0; }
221 static wxList sm_handlers
;
224 bool CreateFromXpm(const char **bits
);
225 bool CreateFromImage(const wxImage
& image
, int depth
);
228 // Creates a bitmap with transparent areas drawn in
230 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, wxColour
& colour
);