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
} ;
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
;
95 wxMask
* m_bitmapMask
; // Optional mask
98 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
100 class WXDLLEXPORT wxBitmapHandler
: public wxObject
102 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
104 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
106 virtual ~wxBitmapHandler() {} // Added min for Mac X
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 inline void SetName(const wxString
& name
) { m_name
= name
; }
115 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
116 inline void SetType(long type
) { m_type
= type
; }
117 inline wxString
GetName() const { return m_name
; }
118 inline wxString
GetExtension() const { return m_extension
; }
119 inline 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 inline wxBitmap(const wxBitmap
& bitmap
)
139 { Ref(bitmap
); if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this); }
141 // Initialize with raw data.
142 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
144 // Initialize with XPM data
145 wxBitmap(const char **data
);
146 wxBitmap(char **data
);
148 // Load a file or resource
149 wxBitmap(const wxString
& name
, long type
= wxBITMAP_TYPE_PICT_RESOURCE
);
151 // Constructor for generalised creation from data
152 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
154 // If depth is omitted, will create a bitmap compatible with the display
155 wxBitmap(int width
, int height
, int depth
= -1);
157 // Convert from wxImage:
158 wxBitmap(const wxImage
& image
, int depth
= -1);
162 wxImage
ConvertToImage() const;
164 // get the given part of bitmap
165 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
167 virtual bool Create(int width
, int height
, int depth
= -1);
168 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
169 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
170 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
173 int GetWidth() const;
174 int GetHeight() const;
175 int GetDepth() const;
176 int GetQuality() const;
177 void SetWidth(int w
);
178 void SetHeight(int h
);
179 void SetDepth(int d
);
180 void SetQuality(int q
);
181 void SetOk(bool isOk
);
183 wxPalette
* GetPalette() const;
184 void SetPalette(const wxPalette
& palette
);
186 wxMask
*GetMask() const;
187 void SetMask(wxMask
*mask
) ;
189 int GetBitmapType() const;
191 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
192 inline bool operator == (const wxBitmap
& bitmap
) { return m_refData
== bitmap
.m_refData
; }
193 inline bool operator != (const wxBitmap
& bitmap
) { return m_refData
!= bitmap
.m_refData
; }
196 static inline wxList
& GetHandlers() { return sm_handlers
; }
197 static void AddHandler(wxBitmapHandler
*handler
);
198 static void InsertHandler(wxBitmapHandler
*handler
);
199 static bool RemoveHandler(const wxString
& name
);
200 static wxBitmapHandler
*FindHandler(const wxString
& name
);
201 static wxBitmapHandler
*FindHandler(const wxString
& extension
, long bitmapType
);
202 static wxBitmapHandler
*FindHandler(long bitmapType
);
204 static void InitStandardHandlers();
205 static void CleanUpHandlers();
207 static wxList sm_handlers
;
209 // TODO: Implementation
211 void SetHBITMAP(WXHBITMAP bmp
);
212 WXHBITMAP
GetHBITMAP() const;
214 PicHandle
GetPict() const;
216 bool FreeResource(bool force
= FALSE
);