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
;
31 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
32 void wxMacDestroyGWorld( GWorldPtr gw
) ;
33 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
34 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
35 CTabHandle
wxMacCreateColorTable( int numColors
) ;
37 // A mask is a mono bitmap used for drawing bitmaps
39 class WXDLLEXPORT wxMask
: public wxObject
41 DECLARE_DYNAMIC_CLASS(wxMask
)
46 // Construct a mask from a bitmap and a colour indicating
47 // the transparent area
48 wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
);
50 // Construct a mask from a bitmap and a palette index indicating
51 // the transparent area
52 wxMask(const wxBitmap
& bitmap
, int paletteIndex
);
54 // Construct a mask from a mono bitmap (copies the bitmap).
55 wxMask(const wxBitmap
& bitmap
);
59 bool Create(const wxBitmap
& bitmap
, const wxColour
& colour
);
60 bool Create(const wxBitmap
& bitmap
, int paletteIndex
);
61 bool Create(const wxBitmap
& bitmap
);
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
} ;
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
;
93 wxMask
* m_bitmapMask
; // Optional mask
96 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
98 class WXDLLEXPORT wxBitmapHandler
: public wxObject
100 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
102 wxBitmapHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; };
104 virtual ~wxBitmapHandler() {} // Added min for Mac X
107 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
108 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
109 int desiredWidth
, int desiredHeight
);
110 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
112 inline void SetName(const wxString
& name
) { m_name
= name
; }
113 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
114 inline void SetType(long type
) { m_type
= type
; }
115 inline wxString
GetName() const { return m_name
; }
116 inline wxString
GetExtension() const { return m_extension
; }
117 inline long GetType() const { return m_type
; }
120 wxString m_extension
;
124 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
126 class WXDLLEXPORT wxBitmap
: public wxGDIObject
128 DECLARE_DYNAMIC_CLASS(wxBitmap
)
130 friend class WXDLLEXPORT wxBitmapHandler
;
133 wxBitmap(); // Platform-specific
136 inline wxBitmap(const wxBitmap
& bitmap
)
137 { Ref(bitmap
); if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this); }
139 // Initialize with raw data.
140 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
142 // Initialize with XPM data
143 wxBitmap(const char **data
);
144 wxBitmap(char **data
);
146 // Load a file or resource
147 wxBitmap(const wxString
& name
, long type
= wxBITMAP_TYPE_PICT_RESOURCE
);
149 // Constructor for generalised creation from data
150 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
152 // If depth is omitted, will create a bitmap compatible with the display
153 wxBitmap(int width
, int height
, int depth
= -1);
156 virtual bool Create(int width
, int height
, int depth
= -1);
157 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
158 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
159 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
161 inline bool Ok() const { return (M_BITMAPDATA
&& M_BITMAPDATA
->m_ok
); }
162 inline int GetWidth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_width
: 0); }
163 inline int GetHeight() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_height
: 0); }
164 inline int GetDepth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_depth
: 0); }
165 inline int GetQuality() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_quality
: 0); }
166 void SetWidth(int w
);
167 void SetHeight(int h
);
168 void SetDepth(int d
);
169 void SetQuality(int q
);
170 void SetOk(bool isOk
);
172 inline wxPalette
* GetPalette() const { return (M_BITMAPDATA
? (& M_BITMAPDATA
->m_bitmapPalette
) : (wxPalette
*) NULL
); }
173 void SetPalette(const wxPalette
& palette
);
175 inline wxMask
*GetMask() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_bitmapMask
: (wxMask
*) NULL
); }
176 void SetMask(wxMask
*mask
) ;
178 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
179 inline bool operator == (const wxBitmap
& bitmap
) { return m_refData
== bitmap
.m_refData
; }
180 inline bool operator != (const wxBitmap
& bitmap
) { return m_refData
!= bitmap
.m_refData
; }
183 static inline wxList
& GetHandlers() { return sm_handlers
; }
184 static void AddHandler(wxBitmapHandler
*handler
);
185 static void InsertHandler(wxBitmapHandler
*handler
);
186 static bool RemoveHandler(const wxString
& name
);
187 static wxBitmapHandler
*FindHandler(const wxString
& name
);
188 static wxBitmapHandler
*FindHandler(const wxString
& extension
, long bitmapType
);
189 static wxBitmapHandler
*FindHandler(long bitmapType
);
191 static void InitStandardHandlers();
192 static void CleanUpHandlers();
194 static wxList sm_handlers
;
196 // TODO: Implementation
198 void SetHBITMAP(WXHBITMAP bmp
);
199 inline WXHBITMAP
GetHBITMAP() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hBitmap
: 0); }
201 bool FreeResource(bool force
= FALSE
);