]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/bitmap.h
135805a5ae587e468d16fe818ba7f12d70290f7d
[wxWidgets.git] / include / wx / gtk / bitmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.h
3 // Purpose:
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifndef __GTKBITMAPH__
12 #define __GTKBITMAPH__
13
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
22 #include "wx/gdiobj.h"
23 #include "wx/rawbmp.h"
24
25 #ifdef __WXGTK20__
26 typedef struct _GdkPixbuf GdkPixbuf;
27 #endif
28
29 //-----------------------------------------------------------------------------
30 // classes
31 //-----------------------------------------------------------------------------
32
33 class wxMask;
34 class wxBitmap;
35 class wxImage;
36
37 //-----------------------------------------------------------------------------
38 // wxMask
39 //-----------------------------------------------------------------------------
40
41 class wxMask: public wxObject
42 {
43 public:
44 wxMask();
45 wxMask( const wxBitmap& bitmap, const wxColour& colour );
46 wxMask( const wxBitmap& bitmap, int paletteIndex );
47 wxMask( const wxBitmap& bitmap );
48 ~wxMask();
49
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)
61 };
62
63 //-----------------------------------------------------------------------------
64 // wxBitmap
65 //-----------------------------------------------------------------------------
66
67 class wxBitmap: public wxBitmapBase
68 {
69 public:
70 wxBitmap();
71 wxBitmap( int width, int height, int depth = -1 );
72 wxBitmap( const char bits[], int width, int height, int depth = 1 );
73 wxBitmap( const char **bits ) { (void)CreateFromXpm(bits); }
74 wxBitmap( char **bits ) { (void)CreateFromXpm((const char **)bits); }
75 wxBitmap( const wxBitmap& bmp );
76 wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_XPM );
77 wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); }
78 ~wxBitmap();
79 wxBitmap& operator = ( const wxBitmap& bmp );
80 bool operator == ( const wxBitmap& bmp ) const;
81 bool operator != ( const wxBitmap& bmp ) const;
82 bool Ok() const;
83
84 bool Create(int width, int height, int depth = -1);
85
86 int GetHeight() const;
87 int GetWidth() const;
88 int GetDepth() const;
89
90 wxImage ConvertToImage() const;
91
92 // copies the contents and mask of the given (colour) icon to the bitmap
93 virtual bool CopyFromIcon(const wxIcon& icon);
94
95 wxMask *GetMask() const;
96 void SetMask( wxMask *mask );
97
98 wxBitmap GetSubBitmap( const wxRect& rect ) const;
99
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 );
103
104 #if wxUSE_PALETTE
105 wxPalette *GetPalette() const;
106 void SetPalette(const wxPalette& palette);
107 wxPalette *GetColourMap() const { return GetPalette(); };
108 #endif // wxUSE_PALETTE
109
110 static void InitStandardHandlers();
111
112 // implementation
113 // --------------
114
115 void SetHeight( int height );
116 void SetWidth( int width );
117 void SetDepth( int depth );
118 void SetPixmap( GdkPixmap *pixmap );
119 void SetBitmap( GdkBitmap *bitmap );
120 #ifdef __WXGTK20__
121 void SetPixbuf(GdkPixbuf *pixbuf);
122 #endif
123
124 GdkPixmap *GetPixmap() const;
125 GdkBitmap *GetBitmap() const;
126 bool HasPixmap() const;
127 #ifdef __WXGTK20__
128 bool HasPixbuf() const;
129 GdkPixbuf *GetPixbuf() const;
130 #endif
131
132 // Basically, this corresponds to Win32 StretchBlt()
133 wxBitmap Rescale( int clipx, int clipy, int clipwidth, int clipheight, int width, int height );
134
135 // raw bitmap access support functions
136 void *GetRawData(wxPixelDataBase& data, int bpp);
137 void UngetRawData(wxPixelDataBase& data);
138
139 protected:
140 bool CreateFromXpm(const char **bits);
141 bool CreateFromImage(const wxImage& image, int depth);
142
143 private:
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
162 friend class wxBitmapHandler;
163
164 private:
165 DECLARE_DYNAMIC_CLASS(wxBitmap)
166 };
167
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
188 #endif // __GTKBITMAPH__