1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class interface
4 // Author: Vaclav Slavik
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_BITMAP_H_BASE_
13 #define _WX_BITMAP_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #include "wx/object.h"
21 #include "wx/string.h"
22 #include "wx/gdiobj.h"
23 #include "wx/gdicmn.h" // for wxBitmapType
25 class WXDLLEXPORT wxBitmap
;
26 class WXDLLEXPORT wxBitmapHandler
;
27 class WXDLLEXPORT wxImage
;
28 class WXDLLEXPORT wxMask
;
29 class WXDLLEXPORT wxPalette
;
31 #if defined(__WXMGL__) || \
32 defined(__WXMAC__) || \
33 defined(__WXGTK__) || \
34 defined(__WXCOCOA__) || \
35 defined(__WXMOTIF__) || \
37 // Only used by some ports
38 // FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
40 // ----------------------------------------------------------------------------
41 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
43 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxBitmapHandlerBase
: public wxObject
51 , m_type(wxBITMAP_TYPE_INVALID
)
54 virtual ~wxBitmapHandlerBase() { }
56 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
57 int width
, int height
, int depth
= 1) = 0;
58 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
59 int desiredWidth
, int desiredHeight
) = 0;
60 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
61 int type
, const wxPalette
*palette
= NULL
) = 0;
63 void SetName(const wxString
& name
) { m_name
= name
; }
64 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
65 void SetType(wxBitmapType type
) { m_type
= type
; }
66 wxString
GetName() const { return m_name
; }
67 wxString
GetExtension() const { return m_extension
; }
68 wxBitmapType
GetType() const { return m_type
; }
76 DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase
)
79 class WXDLLEXPORT wxBitmapBase
: public wxGDIObject
82 wxBitmapBase() : wxGDIObject() {}
83 virtual ~wxBitmapBase() {}
86 Derived class must implement these:
89 wxBitmap(int width, int height, int depth = -1);
90 wxBitmap(const char bits[], int width, int height, int depth = 1);
91 wxBitmap(const char **bits);
92 wxBitmap(char **bits);
93 wxBitmap(const wxBitmap& bmp);
94 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
95 wxBitmap(const wxImage& image, int depth = -1);
96 wxBitmap& operator = (const wxBitmap& bmp);
97 bool operator == (const wxBitmap& bmp) const;
98 bool operator != (const wxBitmap& bmp) const;
100 bool Create(int width, int height, int depth = -1);
102 static void InitStandardHandlers();
105 virtual bool Ok() const = 0;
107 virtual int GetHeight() const = 0;
108 virtual int GetWidth() const = 0;
109 virtual int GetDepth() const = 0;
111 virtual wxImage
ConvertToImage() const = 0;
113 virtual wxMask
*GetMask() const = 0;
114 virtual void SetMask(wxMask
*mask
) = 0;
116 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const = 0;
118 virtual bool SaveFile(const wxString
&name
, wxBitmapType type
,
119 const wxPalette
*palette
= (wxPalette
*)NULL
) const = 0;
120 virtual bool LoadFile(const wxString
&name
, wxBitmapType type
) = 0;
123 If raw bitmap access is supported (see wx/rawbmp.h), the following
124 methods should be implemented:
126 virtual bool GetRawData(wxRawBitmapData *data) = 0;
127 virtual void UngetRawData(wxRawBitmapData *data) = 0;
131 virtual wxPalette
*GetPalette() const = 0;
132 virtual void SetPalette(const wxPalette
& palette
) = 0;
133 #endif // wxUSE_PALETTE
135 // copies the contents and mask of the given (colour) icon to the bitmap
136 virtual bool CopyFromIcon(const wxIcon
& icon
) = 0;
139 virtual void SetHeight(int height
) = 0;
140 virtual void SetWidth(int width
) = 0;
141 virtual void SetDepth(int depth
) = 0;
144 static inline wxList
& GetHandlers() { return sm_handlers
; }
145 static void AddHandler(wxBitmapHandlerBase
*handler
);
146 static void InsertHandler(wxBitmapHandlerBase
*handler
);
147 static bool RemoveHandler(const wxString
& name
);
148 static wxBitmapHandler
*FindHandler(const wxString
& name
);
149 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType bitmapType
);
150 static wxBitmapHandler
*FindHandler(wxBitmapType bitmapType
);
152 //static void InitStandardHandlers();
153 // (wxBitmap must implement this one)
155 static void CleanUpHandlers();
158 static wxList sm_handlers
;
160 DECLARE_ABSTRACT_CLASS(wxBitmapBase
)
164 #if defined(__WXPALMOS__)
165 #include "wx/palmos/bitmap.h"
166 #elif defined(__WXMSW__)
167 #include "wx/msw/bitmap.h"
168 #elif defined(__WXMOTIF__)
169 #include "wx/x11/bitmap.h"
170 #elif defined(__WXGTK20__)
171 #include "wx/gtk/bitmap.h"
172 #elif defined(__WXGTK__)
173 #include "wx/gtk1/bitmap.h"
174 #elif defined(__WXX11__)
175 #include "wx/x11/bitmap.h"
176 #elif defined(__WXMGL__)
177 #include "wx/mgl/bitmap.h"
178 #elif defined(__WXMAC__)
179 #include "wx/mac/bitmap.h"
180 #elif defined(__WXCOCOA__)
181 #include "wx/cocoa/bitmap.h"
182 #elif defined(__WXPM__)
183 #include "wx/os2/bitmap.h"
187 // _WX_BITMAP_H_BASE_