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 height
, int widtdh
, 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 bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
105 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
106 int desiredWidth
, int desiredHeight
);
107 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
109 inline void SetName(const wxString
& name
) { m_name
= name
; }
110 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
111 inline void SetType(long type
) { m_type
= type
; }
112 inline wxString
GetName() const { return m_name
; }
113 inline wxString
GetExtension() const { return m_extension
; }
114 inline long GetType() const { return m_type
; }
117 wxString m_extension
;
121 #define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData())
123 class WXDLLEXPORT wxBitmap
: public wxGDIObject
125 DECLARE_DYNAMIC_CLASS(wxBitmap
)
127 friend class WXDLLEXPORT wxBitmapHandler
;
130 wxBitmap(); // Platform-specific
133 inline wxBitmap(const wxBitmap
& bitmap
)
134 { Ref(bitmap
); if ( wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this); }
136 // Initialize with raw data.
137 wxBitmap(const char bits
[], int width
, int height
, int depth
= 1);
139 // Initialize with XPM data
140 wxBitmap(const char **data
);
142 // Load a file or resource
143 wxBitmap(const wxString
& name
, long type
= wxBITMAP_TYPE_PICT_RESOURCE
);
145 // Constructor for generalised creation from data
146 wxBitmap(void *data
, long type
, int width
, int height
, int depth
= 1);
148 // If depth is omitted, will create a bitmap compatible with the display
149 wxBitmap(int width
, int height
, int depth
= -1);
152 virtual bool Create(int width
, int height
, int depth
= -1);
153 virtual bool Create(void *data
, long type
, int width
, int height
, int depth
= 1);
154 virtual bool LoadFile(const wxString
& name
, long type
= wxBITMAP_TYPE_BMP_RESOURCE
);
155 virtual bool SaveFile(const wxString
& name
, int type
, const wxPalette
*cmap
= NULL
);
157 inline bool Ok() const { return (M_BITMAPDATA
&& M_BITMAPDATA
->m_ok
); }
158 inline int GetWidth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_width
: 0); }
159 inline int GetHeight() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_height
: 0); }
160 inline int GetDepth() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_depth
: 0); }
161 inline int GetQuality() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_quality
: 0); }
162 void SetWidth(int w
);
163 void SetHeight(int h
);
164 void SetDepth(int d
);
165 void SetQuality(int q
);
166 void SetOk(bool isOk
);
168 inline wxPalette
* GetPalette() const { return (M_BITMAPDATA
? (& M_BITMAPDATA
->m_bitmapPalette
) : (wxPalette
*) NULL
); }
169 void SetPalette(const wxPalette
& palette
);
171 inline wxMask
*GetMask() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_bitmapMask
: (wxMask
*) NULL
); }
172 void SetMask(wxMask
*mask
) ;
174 inline wxBitmap
& operator = (const wxBitmap
& bitmap
) { if (*this == bitmap
) return (*this); Ref(bitmap
); return *this; }
175 inline bool operator == (const wxBitmap
& bitmap
) { return m_refData
== bitmap
.m_refData
; }
176 inline bool operator != (const wxBitmap
& bitmap
) { return m_refData
!= bitmap
.m_refData
; }
179 static inline wxList
& GetHandlers() { return sm_handlers
; }
180 static void AddHandler(wxBitmapHandler
*handler
);
181 static void InsertHandler(wxBitmapHandler
*handler
);
182 static bool RemoveHandler(const wxString
& name
);
183 static wxBitmapHandler
*FindHandler(const wxString
& name
);
184 static wxBitmapHandler
*FindHandler(const wxString
& extension
, long bitmapType
);
185 static wxBitmapHandler
*FindHandler(long bitmapType
);
187 static void InitStandardHandlers();
188 static void CleanUpHandlers();
190 static wxList sm_handlers
;
192 // TODO: Implementation
194 void SetHBITMAP(WXHBITMAP bmp
);
195 inline WXHBITMAP
GetHBITMAP() const { return (M_BITMAPDATA
? M_BITMAPDATA
->m_hBitmap
: 0); }
196 bool FreeResource(bool force
= FALSE
);