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