]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
0b04c4e0 | 2 | // Name: wx/gtk/bitmap.h |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
6f65e337 | 5 | // RCS-ID: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | ||
11 | #ifndef __GTKBITMAPH__ | |
12 | #define __GTKBITMAPH__ | |
13 | ||
c801d85f KB |
14 | #include "wx/defs.h" |
15 | #include "wx/object.h" | |
16 | #include "wx/string.h" | |
17 | #include "wx/palette.h" | |
58c837a4 | 18 | #include "wx/gdiobj.h" |
c801d85f | 19 | |
feac7937 VS |
20 | #ifdef __WXGTK20__ |
21 | typedef struct _GdkPixbuf GdkPixbuf; | |
22 | #endif | |
23 | ||
f383c5b8 VZ |
24 | class WXDLLEXPORT wxPixelDataBase; |
25 | ||
c801d85f KB |
26 | //----------------------------------------------------------------------------- |
27 | // classes | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
20123d49 MW |
30 | class WXDLLIMPEXP_CORE wxMask; |
31 | class WXDLLIMPEXP_CORE wxBitmap; | |
32 | class WXDLLIMPEXP_CORE wxImage; | |
c801d85f KB |
33 | |
34 | //----------------------------------------------------------------------------- | |
35 | // wxMask | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
20123d49 | 38 | class WXDLLIMPEXP_CORE wxMask: public wxObject |
c801d85f | 39 | { |
fd0eed64 | 40 | public: |
8636aed8 RR |
41 | wxMask(); |
42 | wxMask( const wxBitmap& bitmap, const wxColour& colour ); | |
0b04c4e0 | 43 | #if wxUSE_PALETTE |
8636aed8 | 44 | wxMask( const wxBitmap& bitmap, int paletteIndex ); |
0b04c4e0 | 45 | #endif // wxUSE_PALETTE |
8636aed8 RR |
46 | wxMask( const wxBitmap& bitmap ); |
47 | ~wxMask(); | |
0b04c4e0 | 48 | |
8636aed8 | 49 | bool Create( const wxBitmap& bitmap, const wxColour& colour ); |
0b04c4e0 | 50 | #if wxUSE_PALETTE |
8636aed8 | 51 | bool Create( const wxBitmap& bitmap, int paletteIndex ); |
0b04c4e0 | 52 | #endif // wxUSE_PALETTE |
8636aed8 RR |
53 | bool Create( const wxBitmap& bitmap ); |
54 | ||
55 | // implementation | |
56 | GdkBitmap *m_bitmap; | |
0b04c4e0 | 57 | |
8636aed8 | 58 | GdkBitmap *GetBitmap() const; |
0b04c4e0 | 59 | |
8636aed8 RR |
60 | private: |
61 | DECLARE_DYNAMIC_CLASS(wxMask) | |
c801d85f KB |
62 | }; |
63 | ||
64 | //----------------------------------------------------------------------------- | |
65 | // wxBitmap | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
20123d49 | 68 | class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase |
c801d85f | 69 | { |
fd0eed64 | 70 | public: |
8636aed8 RR |
71 | wxBitmap(); |
72 | wxBitmap( int width, int height, int depth = -1 ); | |
73 | wxBitmap( const char bits[], int width, int height, int depth = 1 ); | |
e838cc14 VZ |
74 | wxBitmap( const char **bits ) { (void)CreateFromXpm(bits); } |
75 | wxBitmap( char **bits ) { (void)CreateFromXpm((const char **)bits); } | |
8636aed8 | 76 | wxBitmap( const wxBitmap& bmp ); |
4611dd06 | 77 | wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM ); |
fd859211 | 78 | wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); } |
8636aed8 RR |
79 | ~wxBitmap(); |
80 | wxBitmap& operator = ( const wxBitmap& bmp ); | |
f6bcfd97 BP |
81 | bool operator == ( const wxBitmap& bmp ) const; |
82 | bool operator != ( const wxBitmap& bmp ) const; | |
8636aed8 RR |
83 | bool Ok() const; |
84 | ||
c826213d | 85 | bool Create(int width, int height, int depth = -1); |
0b04c4e0 | 86 | |
8636aed8 RR |
87 | int GetHeight() const; |
88 | int GetWidth() const; | |
89 | int GetDepth() const; | |
0b04c4e0 | 90 | |
fd859211 | 91 | wxImage ConvertToImage() const; |
8636aed8 | 92 | |
db0aec83 VS |
93 | // copies the contents and mask of the given (colour) icon to the bitmap |
94 | virtual bool CopyFromIcon(const wxIcon& icon); | |
95 | ||
8636aed8 RR |
96 | wxMask *GetMask() const; |
97 | void SetMask( wxMask *mask ); | |
0b04c4e0 | 98 | |
17bec151 | 99 | wxBitmap GetSubBitmap( const wxRect& rect ) const; |
8636aed8 | 100 | |
4611dd06 RR |
101 | bool SaveFile(const wxString &name, wxBitmapType type, |
102 | const wxPalette *palette = (wxPalette *)NULL) const; | |
103 | bool LoadFile(const wxString &name, wxBitmapType type = wxBITMAP_TYPE_XPM ); | |
8636aed8 | 104 | |
4611dd06 | 105 | #if wxUSE_PALETTE |
8636aed8 | 106 | wxPalette *GetPalette() const; |
4611dd06 | 107 | void SetPalette(const wxPalette& palette); |
55e90a2e | 108 | wxPalette *GetColourMap() const { return GetPalette(); }; |
4611dd06 | 109 | #endif // wxUSE_PALETTE |
55e90a2e | 110 | |
4b61c88d | 111 | static void InitStandardHandlers(); |
8bbe427f | 112 | |
8636aed8 | 113 | // implementation |
20e05ffb | 114 | // -------------- |
c801d85f | 115 | |
8636aed8 RR |
116 | void SetHeight( int height ); |
117 | void SetWidth( int width ); | |
118 | void SetDepth( int depth ); | |
119 | void SetPixmap( GdkPixmap *pixmap ); | |
82ea63e6 | 120 | void SetBitmap( GdkBitmap *bitmap ); |
feac7937 VS |
121 | #ifdef __WXGTK20__ |
122 | void SetPixbuf(GdkPixbuf *pixbuf); | |
123 | #endif | |
8bbe427f | 124 | |
8636aed8 RR |
125 | GdkPixmap *GetPixmap() const; |
126 | GdkBitmap *GetBitmap() const; | |
feac7937 VS |
127 | bool HasPixmap() const; |
128 | #ifdef __WXGTK20__ | |
129 | bool HasPixbuf() const; | |
130 | GdkPixbuf *GetPixbuf() const; | |
131 | #endif | |
0b04c4e0 | 132 | |
783da845 RR |
133 | // Basically, this corresponds to Win32 StretchBlt() |
134 | wxBitmap Rescale( int clipx, int clipy, int clipwidth, int clipheight, int width, int height ); | |
0b04c4e0 | 135 | |
284f2b59 RR |
136 | // raw bitmap access support functions |
137 | void *GetRawData(wxPixelDataBase& data, int bpp); | |
138 | void UngetRawData(wxPixelDataBase& data); | |
139 | ||
0ff2a74d RR |
140 | bool HasAlpha() const; |
141 | void UseAlpha(); | |
d2400c3f | 142 | |
e838cc14 VZ |
143 | protected: |
144 | bool CreateFromXpm(const char **bits); | |
fd859211 | 145 | bool CreateFromImage(const wxImage& image, int depth); |
e838cc14 | 146 | |
8636aed8 | 147 | private: |
feac7937 VS |
148 | // to be called from CreateFromImage only! |
149 | bool CreateFromImageAsBitmap(const wxImage& image); | |
150 | bool CreateFromImageAsPixmap(const wxImage& image); | |
151 | ||
152 | #ifdef __WXGTK20__ | |
153 | bool CreateFromImageAsPixbuf(const wxImage& image); | |
154 | ||
155 | enum Representation | |
156 | { | |
157 | Pixmap, | |
158 | Pixbuf | |
159 | }; | |
160 | // removes other representations from memory, keeping only 'keep' | |
161 | // (wxBitmap may keep same bitmap e.g. as both pixmap and pixbuf): | |
162 | void PurgeOtherRepresentations(Representation keep); | |
163 | ||
164 | friend class wxMemoryDC; | |
165 | #endif | |
4b61c88d RR |
166 | friend class wxBitmapHandler; |
167 | ||
0b04c4e0 | 168 | private: |
8636aed8 | 169 | DECLARE_DYNAMIC_CLASS(wxBitmap) |
c801d85f KB |
170 | }; |
171 | ||
4b61c88d RR |
172 | //----------------------------------------------------------------------------- |
173 | // wxBitmapHandler | |
174 | //----------------------------------------------------------------------------- | |
175 | ||
20123d49 | 176 | class WXDLLIMPEXP_CORE wxBitmapHandler: public wxBitmapHandlerBase |
4b61c88d RR |
177 | { |
178 | public: | |
179 | wxBitmapHandler() { } | |
180 | virtual ~wxBitmapHandler(); | |
181 | ||
182 | virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); | |
183 | virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
184 | int desiredWidth, int desiredHeight); | |
185 | virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); | |
186 | ||
187 | private: | |
188 | DECLARE_DYNAMIC_CLASS(wxBitmapHandler) | |
189 | }; | |
190 | ||
191 | ||
c801d85f | 192 | #endif // __GTKBITMAPH__ |