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
;
31 // A mask is a mono bitmap used for drawing bitmaps
33 class WXDLLEXPORT wxMask
: public wxObject
35 DECLARE_DYNAMIC_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
);
57 WXPixmap
GetPixmap() const { return m_pixmap
; }
58 void SetPixmap(WXPixmap pixmap
) { m_pixmap
= pixmap
; }
64 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
66 friend class WXDLLEXPORT wxBitmap
;
67 friend class WXDLLEXPORT wxIcon
;
68 friend class WXDLLEXPORT wxCursor
;
79 wxPalette m_bitmapPalette
;
82 wxMask
* m_bitmapMask
; // Optional mask
84 // Motif implementation
89 unsigned long* m_freeColors
;
90 long m_freeColorsCount
;
92 // These 5 variables are for wxControl
93 WXPixmap m_insensPixmap
;
94 WXPixmap m_labelPixmap
;
95 WXPixmap m_armPixmap
;
97 WXImage
* m_insensImage
;
100 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
102 class WXDLLEXPORT wxBitmapHandler
: public wxObject
104 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
106 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
108 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
109 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
110 int desiredWidth
, int desiredHeight
);
111 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
113 void SetName(const wxString
& name
) { m_name
= name
; }
114 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
115 void SetType(long type
) { m_type
= type
; }
116 wxString
GetName() const { return m_name
; }
117 wxString
GetExtension() const { return m_extension
; }
118 long GetType() const { return m_type
; }
121 wxString m_extension
;
125 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
127 class WXDLLEXPORT wxBitmap
: public wxGDIObject
129 DECLARE_DYNAMIC_CLASS(wxBitmap
)
131 friend class WXDLLEXPORT wxBitmapHandler
;
134 wxBitmap(); // Platform-specific
137 wxBitmap(const wxBitmap
& bitmap
)
138 { Ref(bitmap
); if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this); }
140 // Initialize with raw XBM data
141 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
144 wxBitmap(const char **data
) { (void)CreateFromXpm(data
); }
145 wxBitmap(char **data
) { (void)CreateFromXpm((const char **)data
); }
147 // Initialize with XPM data -- deprecated
148 wxBitmap(char **data
, wxControl
* control
);
150 // Load a file or resource
151 wxBitmap(const wxString
& name
, long type
= wxBITMAP_TYPE_XPM
);
153 // Constructor for generalised creation from data
154 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
156 // If depth is omitted, will create a bitmap compatible with the display
157 wxBitmap(int width
, int height
, int depth
= -1);
160 virtual bool Create(int width
, int height
, int depth
= -1);
161 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
163 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
165 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_XPM
);
166 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
168 bool Ok() const { return (M_BITMAPDATA
&& M_BITMAPDATA
->m_ok
); }
169 int GetWidth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_width
: 0); }
170 int GetHeight() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_height
: 0); }
171 int GetDepth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_depth
: 0); }
172 int GetQuality() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_quality
: 0); }
173 void SetWidth(int w
);
174 void SetHeight(int h
);
175 void SetDepth(int d
);
176 void SetQuality(int q
);
177 void SetOk(bool isOk
);
179 wxPalette
* GetPalette() const { return (M_BITMAPDATA
? (& M_BITMAPDATA
->m_bitmapPalette
) : (wxPalette
*) NULL
); }
180 void SetPalette(const wxPalette
& palette
);
182 wxMask
*GetMask() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_bitmapMask
: (wxMask
*) NULL
); }
183 void SetMask(wxMask
*mask
) ;
185 wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
186 bool operator == (const wxBitmap
& bitmap
) const { return m_refData
== bitmap
.m_refData
; }
187 bool operator != (const wxBitmap
& bitmap
) const { return m_refData
!= bitmap
.m_refData
; }
190 static wxList
& GetHandlers() { return sm_handlers
; }
191 static void AddHandler(wxBitmapHandler
*handler
);
192 static void InsertHandler(wxBitmapHandler
*handler
);
193 static bool RemoveHandler(const wxString
& name
);
194 static wxBitmapHandler
*FindHandler(const wxString
& name
);
195 static wxBitmapHandler
*FindHandler(const wxString
& extension
, long bitmapType
);
196 static wxBitmapHandler
*FindHandler(long bitmapType
);
198 static void InitStandardHandlers();
199 static void CleanUpHandlers();
201 // Motif implementation
203 WXDisplay
* GetDisplay() const { return M_BITMAPDATA
->m_display
; }
204 WXPixmap
GetPixmap() const { return (WXPixmap
) M_BITMAPDATA
->m_pixmap
; }
205 virtual WXPixmap
GetLabelPixmap(WXWidget w
) ;
206 virtual WXPixmap
GetArmPixmap(WXWidget w
) ;
207 virtual WXPixmap
GetInsensPixmap(WXWidget w
= (WXWidget
) 0) ;
208 void SetPixmapNull() { M_BITMAPDATA
->m_pixmap
= 0; }
211 static wxList sm_handlers
;
214 bool CreateFromXpm(const char **bits
);
217 // Creates a bitmap with transparent areas drawn in
219 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, wxColour
& colour
);