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