1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
8 // Copyright: (c) AUTHOR
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 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
33 void wxMacDestroyGWorld( GWorldPtr gw
) ;
34 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
35 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
36 CTabHandle
wxMacCreateColorTable( int numColors
) ;
38 // A mask is a mono bitmap used for drawing bitmaps
40 class WXDLLEXPORT wxMask
: public wxObject
42 DECLARE_DYNAMIC_CLASS(wxMask
)
47 // Construct a mask from a bitmap and a colour indicating
48 // the transparent area
49 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
51 // Construct a mask from a bitmap and a palette index indicating
52 // the transparent area
53 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
55 // Construct a mask from a mono bitmap (copies the bitmap).
56 wxMask(const wxBitmap
& bitmap
);
60 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
61 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
62 bool Create(const wxBitmap
& bitmap
);
65 bool PointMasked(int x
, int y
);
66 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
67 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
69 WXHBITMAP m_maskBitmap
;
72 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
74 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
76 friend class WXDLLEXPORT wxBitmap
;
77 friend class WXDLLEXPORT wxIcon
;
78 friend class WXDLLEXPORT wxCursor
;
89 wxPalette m_bitmapPalette
;
96 wxMask
* m_bitmapMask
; // Optional mask
99 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
101 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
103 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
105 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
107 virtual ~wxBitmapHandler() {} // Added min for Mac X
110 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
111 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
112 int desiredWidth
, int desiredHeight
);
113 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
115 inline void SetName(const wxString
& name
) { m_name
= name
; }
116 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
117 inline void SetType(long type
) { m_type
= type
; }
118 inline wxString
GetName() const { return m_name
; }
119 inline wxString
GetExtension() const { return m_extension
; }
120 inline long GetType() const { return m_type
; }
123 wxString m_extension
;
127 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
129 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
131 DECLARE_DYNAMIC_CLASS(wxBitmap
)
133 friend class WXDLLEXPORT wxBitmapHandler
;
136 wxBitmap(); // Platform-specific
139 inline wxBitmap(const wxBitmap
& bitmap
)
140 { Ref(bitmap
); if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this); }
142 // Initialize with raw data.
143 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
145 // Initialize with XPM data
146 bool CreateFromXpm(const char **bits
);
147 wxBitmap(const char **bits
);
148 wxBitmap(char **bits
);
150 // Load a file or resource
151 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
153 // Constructor for generalised creation from data
154 wxBitmap(void *data
, wxBitmapType 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);
159 // Convert from wxImage:
160 wxBitmap(const wxImage
& image
, int depth
= -1);
164 wxImage
ConvertToImage() const;
166 // get the given part of bitmap
167 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
169 virtual bool Create(int width
, int height
, int depth
= -1);
170 virtual bool Create(void *data
, wxBitmapType type
, int width
, int height
, int depth
= 1);
171 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
172 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
174 // copies the contents and mask of the given (colour) icon to the bitmap
175 virtual bool CopyFromIcon(const wxIcon
& icon
);
178 int GetWidth() const;
179 int GetHeight() const;
180 int GetDepth() const;
181 int GetQuality() const;
182 void SetWidth(int w
);
183 void SetHeight(int h
);
184 void SetDepth(int d
);
185 void SetQuality(int q
);
186 void SetOk(bool isOk
);
188 wxPalette
* GetPalette() const;
189 void SetPalette(const wxPalette
& palette
);
191 wxMask
*GetMask() const;
192 void SetMask(wxMask
*mask
) ;
194 int GetBitmapType() const;
196 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
197 inline bool operator == (const wxBitmap
& bitmap
) { return m_refData
== bitmap
.m_refData
; }
198 inline bool operator != (const wxBitmap
& bitmap
) { return m_refData
!= bitmap
.m_refData
; }
201 static inline wxList
& GetHandlers() { return sm_handlers
; }
202 static void AddHandler(wxBitmapHandler
*handler
);
203 static void InsertHandler(wxBitmapHandler
*handler
);
204 static bool RemoveHandler(const wxString
& name
);
205 static wxBitmapHandler
*FindHandler(const wxString
& name
);
206 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType type
);
207 static wxBitmapHandler
*FindHandler(wxBitmapType type
);
209 static void InitStandardHandlers();
210 static void CleanUpHandlers();
212 static wxList sm_handlers
;
214 // TODO: Implementation
216 void SetHBITMAP(WXHBITMAP bmp
);
217 WXHBITMAP
GetHBITMAP() const;
218 void SetHICON(WXHICON ico
);
219 inline WXHICON
GetHICON() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hIcon
: 0); }
221 PicHandle
GetPict() const;
223 bool FreeResource(bool force
= FALSE
);