1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "bitmap.h"
19 #include "wx/palette.h"
22 class WXDLLEXPORT wxDC
;
23 class WXDLLEXPORT wxControl
;
24 class WXDLLEXPORT wxBitmap
;
25 class WXDLLEXPORT wxBitmapHandler
;
26 class WXDLLEXPORT wxIcon
;
27 class WXDLLEXPORT wxCursor
;
28 class WXDLLEXPORT wxImage
;
30 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
31 void wxMacDestroyGWorld( GWorldPtr gw
) ;
32 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
33 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
34 CTabHandle
wxMacCreateColorTable( int numColors
) ;
36 // A mask is a mono bitmap used for drawing bitmaps
38 class WXDLLEXPORT wxMask
: public wxObject
40 DECLARE_DYNAMIC_CLASS(wxMask
)
45 // Construct a mask from a bitmap and a colour indicating
46 // the transparent area
47 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
49 // Construct a mask from a bitmap and a palette index indicating
50 // the transparent area
51 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
53 // Construct a mask from a mono bitmap (copies the bitmap).
54 wxMask(const wxBitmap
& bitmap
);
58 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
59 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
60 bool Create(const wxBitmap
& bitmap
);
63 bool PointMasked(int x
, int y
);
64 inline WXHBITMAP
GetMaskBitmap() const { return m_maskBitmap
; }
65 inline void SetMaskBitmap(WXHBITMAP bmp
) { m_maskBitmap
= bmp
; }
67 WXHBITMAP m_maskBitmap
;
70 enum { kMacBitmapTypeUnknownType
, kMacBitmapTypeGrafWorld
, kMacBitmapTypePict
, kMacBitmapTypeIcon
} ;
72 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
74 friend class WXDLLEXPORT wxBitmap
;
75 friend class WXDLLEXPORT wxIcon
;
76 friend class WXDLLEXPORT wxCursor
;
87 wxPalette m_bitmapPalette
;
94 wxMask
* m_bitmapMask
; // Optional mask
97 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
99 class WXDLLEXPORT wxBitmapHandler
: public wxBitmapHandlerBase
101 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
103 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
105 virtual ~wxBitmapHandler() {} // Added min for Mac X
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(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
113 inline void SetName(const wxString
& name
) { m_name
= name
; }
114 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
115 inline void SetType(long type
) { m_type
= type
; }
116 inline wxString
GetName() const { return m_name
; }
117 inline wxString
GetExtension() const { return m_extension
; }
118 inline long GetType() const { return m_type
; }
121 wxString m_extension
;
125 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
127 class WXDLLEXPORT wxBitmap
: public wxBitmapBase
129 DECLARE_DYNAMIC_CLASS(wxBitmap
)
131 friend class WXDLLEXPORT wxBitmapHandler
;
134 wxBitmap(); // Platform-specific
137 inline wxBitmap(const wxBitmap
& bitmap
)
138 { Ref(bitmap
); if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this); }
140 // Initialize with raw data.
141 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
143 // Initialize with XPM data
144 bool CreateFromXpm(const char **bits
);
145 wxBitmap(const char **bits
);
146 wxBitmap(char **bits
);
148 // Load a file or resource
149 wxBitmap(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_PICT_RESOURCE
);
151 // Constructor for generalised creation from data
152 wxBitmap(void *data
, wxBitmapType 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
, wxBitmapType type
, int width
, int height
, int depth
= 1);
169 virtual bool LoadFile(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_BMP_RESOURCE
);
170 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
, const wxPalette
*cmap
= NULL
) const;
172 // copies the contents and mask of the given (colour) icon to the bitmap
173 virtual bool CopyFromIcon(const wxIcon
& icon
);
176 int GetWidth() const;
177 int GetHeight() const;
178 int GetDepth() const;
179 int GetQuality() const;
180 void SetWidth(int w
);
181 void SetHeight(int h
);
182 void SetDepth(int d
);
183 void SetQuality(int q
);
184 void SetOk(bool isOk
);
186 wxPalette
* GetPalette() const;
187 void SetPalette(const wxPalette
& palette
);
189 wxMask
*GetMask() const;
190 void SetMask(wxMask
*mask
) ;
192 int GetBitmapType() const;
194 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
195 inline bool operator == (const wxBitmap
& bitmap
) { return m_refData
== bitmap
.m_refData
; }
196 inline bool operator != (const wxBitmap
& bitmap
) { return m_refData
!= bitmap
.m_refData
; }
199 static inline wxList
& GetHandlers() { return sm_handlers
; }
200 static void AddHandler(wxBitmapHandler
*handler
);
201 static void InsertHandler(wxBitmapHandler
*handler
);
202 static bool RemoveHandler(const wxString
& name
);
203 static wxBitmapHandler
*FindHandler(const wxString
& name
);
204 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType type
);
205 static wxBitmapHandler
*FindHandler(wxBitmapType type
);
207 static void InitStandardHandlers();
208 static void CleanUpHandlers();
211 // TODO: Implementation
213 void SetHBITMAP(WXHBITMAP bmp
);
214 WXHBITMAP
GetHBITMAP() const;
215 void SetHICON(WXHICON ico
);
216 inline WXHICON
GetHICON() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hIcon
: 0); }
218 PicHandle
GetPict() const;
220 bool FreeResource(bool force
= FALSE
);