1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmap class interface
4 // Author: Vaclav Slavik
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_BITMAP_H_BASE_
13 #define _WX_BITMAP_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #if defined(__GNUG__) && !defined(__APPLE__)
20 #pragma interface "bitmapbase.h"
24 #include "wx/object.h"
25 #include "wx/string.h"
26 #include "wx/gdiobj.h"
27 #include "wx/gdicmn.h" // for wxBitmapType
29 class WXDLLEXPORT wxBitmap
;
30 class WXDLLEXPORT wxBitmapHandler
;
31 class WXDLLEXPORT wxImage
;
32 class WXDLLEXPORT wxMask
;
33 class WXDLLEXPORT wxPalette
;
35 #if defined(__WXMGL__) || defined(__WXMAC__) || defined(__WXCOCOA__) || defined(__WXMOTIF__) || defined(__WXX11__)
36 // Only used by some ports
37 // FIXME -- make all ports (but MSW which uses wxGDIImage) use these base classes
39 // ----------------------------------------------------------------------------
40 // wxBitmapHandler: class which knows how to create/load/save bitmaps in
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxBitmapHandlerBase
: public wxObject
50 , m_type(wxBITMAP_TYPE_INVALID
)
53 virtual ~wxBitmapHandlerBase() { }
55 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
,
56 int width
, int height
, int depth
= 1) = 0;
57 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
58 int desiredWidth
, int desiredHeight
) = 0;
59 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
,
60 int type
, const wxPalette
*palette
= NULL
) = 0;
62 void SetName(const wxString
& name
) { m_name
= name
; }
63 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
64 void SetType(wxBitmapType type
) { m_type
= type
; }
65 wxString
GetName() const { return m_name
; }
66 wxString
GetExtension() const { return m_extension
; }
67 wxBitmapType
GetType() const { return m_type
; }
74 DECLARE_ABSTRACT_CLASS(wxBitmapHandlerBase
)
77 class WXDLLEXPORT wxBitmapBase
: public wxGDIObject
80 wxBitmapBase() : wxGDIObject() {}
81 virtual ~wxBitmapBase() {}
84 Derived class must implement these:
87 wxBitmap(int width, int height, int depth = -1);
88 wxBitmap(const char bits[], int width, int height, int depth = 1);
89 wxBitmap(const char **bits);
90 wxBitmap(char **bits);
91 wxBitmap(const wxBitmap& bmp);
92 wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM);
93 wxBitmap(const wxImage& image, int depth = -1);
94 wxBitmap& operator = (const wxBitmap& bmp);
95 bool operator == (const wxBitmap& bmp) const;
96 bool operator != (const wxBitmap& bmp) const;
98 bool Create(int width, int height, int depth = -1);
100 static void InitStandardHandlers();
103 virtual bool Ok() const = 0;
105 virtual int GetHeight() const = 0;
106 virtual int GetWidth() const = 0;
107 virtual int GetDepth() const = 0;
109 virtual wxImage
ConvertToImage() const = 0;
111 virtual wxMask
*GetMask() const = 0;
112 virtual void SetMask(wxMask
*mask
) = 0;
114 virtual wxBitmap
GetSubBitmap(const wxRect
& rect
) const = 0;
116 virtual bool SaveFile(const wxString
&name
, wxBitmapType type
,
117 const wxPalette
*palette
= (wxPalette
*)NULL
) const = 0;
118 virtual bool LoadFile(const wxString
&name
, wxBitmapType type
) = 0;
121 If raw bitmap access is supported (see wx/rawbmp.h), the following
122 methods should be implemented:
124 virtual bool GetRawData(wxRawBitmapData *data) = 0;
125 virtual void UngetRawData(wxRawBitmapData *data) = 0;
129 virtual wxPalette
*GetPalette() const = 0;
130 virtual void SetPalette(const wxPalette
& palette
) = 0;
131 #endif // wxUSE_PALETTE
133 #if WXWIN_COMPATIBILITY
134 wxPalette
*GetColourMap() const { return GetPalette(); }
135 void SetColourMap(wxPalette
*cmap
) { SetPalette(*cmap
); };
136 #endif // WXWIN_COMPATIBILITY
138 // copies the contents and mask of the given (colour) icon to the bitmap
139 virtual bool CopyFromIcon(const wxIcon
& icon
) = 0;
142 virtual void SetHeight(int height
) = 0;
143 virtual void SetWidth(int width
) = 0;
144 virtual void SetDepth(int depth
) = 0;
147 static inline wxList
& GetHandlers() { return sm_handlers
; }
148 static void AddHandler(wxBitmapHandlerBase
*handler
);
149 static void InsertHandler(wxBitmapHandlerBase
*handler
);
150 static bool RemoveHandler(const wxString
& name
);
151 static wxBitmapHandler
*FindHandler(const wxString
& name
);
152 static wxBitmapHandler
*FindHandler(const wxString
& extension
, wxBitmapType bitmapType
);
153 static wxBitmapHandler
*FindHandler(wxBitmapType bitmapType
);
155 //static void InitStandardHandlers();
156 // (wxBitmap must implement this one)
158 static void CleanUpHandlers();
161 static wxList sm_handlers
;
163 DECLARE_ABSTRACT_CLASS(wxBitmapBase
)
167 #if defined(__WXMSW__)
168 #include "wx/msw/bitmap.h"
169 #elif defined(__WXMOTIF__)
170 #include "wx/motif/bitmap.h"
171 #elif defined(__WXGTK__)
172 #include "wx/gtk/bitmap.h"
173 #elif defined(__WXX11__)
174 #include "wx/x11/bitmap.h"
175 #elif defined(__WXMGL__)
176 #include "wx/mgl/bitmap.h"
177 #elif defined(__WXMAC__)
178 #include "wx/mac/bitmap.h"
179 #elif defined(__WXCOCOA__)
180 #include "wx/cocoa/bitmap.h"
181 #elif defined(__WXPM__)
182 #include "wx/os2/bitmap.h"
186 // _WX_BITMAP_H_BASE_