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