]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
1. added wxTreeCtrl::GetLastChild (modified MSW, GTK, generic and docs)
[wxWidgets.git] / include / wx / image.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: image.h
3 // Purpose: wxImage class
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_IMAGE_H_
11 #define _WX_IMAGE_H_
12
13 #ifdef __GNUG__
14 #pragma interface "image.h"
15 #endif
16
17 #include "wx/setup.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/gdicmn.h"
21
22 #if wxUSE_STREAMS
23 #include "wx/stream.h"
24 #endif
25
26 //-----------------------------------------------------------------------------
27 // classes
28 //-----------------------------------------------------------------------------
29
30 class WXDLLEXPORT wxImageHandler;
31 #if wxUSE_LIBPNG
32 class WXDLLEXPORT wxPNGHandler;
33 #endif
34 class WXDLLEXPORT wxBMPHandler;
35 class WXDLLEXPORT wxImage;
36
37 class WXDLLEXPORT wxBitmap;
38
39 //-----------------------------------------------------------------------------
40 // wxImageHandler
41 //-----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxImageHandler: public wxObject
44 {
45 DECLARE_DYNAMIC_CLASS(wxImageHandler)
46
47 public:
48 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
49
50 #if wxUSE_STREAMS
51 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
52 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
53 #endif
54
55 inline void SetName(const wxString& name) { m_name = name; }
56 inline void SetExtension(const wxString& ext) { m_extension = ext; }
57 inline void SetType(long type) { m_type = type; }
58 inline wxString GetName() const { return m_name; }
59 inline wxString GetExtension() const { return m_extension; }
60 inline long GetType() const { return m_type; }
61
62 protected:
63 wxString m_name;
64 wxString m_extension;
65 long m_type;
66
67 };
68
69 //-----------------------------------------------------------------------------
70 // wxPNGHandler
71 //-----------------------------------------------------------------------------
72
73 #if wxUSE_LIBPNG
74 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
75 {
76 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
77
78 public:
79
80 inline wxPNGHandler()
81 {
82 m_name = "PNG file";
83 m_extension = "png";
84 m_type = wxBITMAP_TYPE_PNG;
85 };
86
87 #if wxUSE_STREAMS
88 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
89 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
90 #endif
91
92 };
93 #endif
94
95 //-----------------------------------------------------------------------------
96 // wxBMPHandler
97 //-----------------------------------------------------------------------------
98
99 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
100 {
101 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
102
103 public:
104
105 inline wxBMPHandler()
106 {
107 m_name = "BMP file";
108 m_extension = "bmp";
109 m_type = wxBITMAP_TYPE_BMP;
110 };
111
112 #if wxUSE_STREAMS
113 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
114 #endif
115 };
116
117 //-----------------------------------------------------------------------------
118 // wxImage
119 //-----------------------------------------------------------------------------
120
121 class WXDLLEXPORT wxImage: public wxObject
122 {
123 DECLARE_DYNAMIC_CLASS(wxImage)
124
125 friend class WXDLLEXPORT wxImageHandler;
126
127 public:
128
129 wxImage();
130 wxImage( int width, int height );
131 wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
132 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
133
134 wxImage( const wxImage& image );
135 wxImage( const wxImage* image );
136
137 // these functions get implemented in /src/(platform)/bitmap.cpp
138 wxImage( const wxBitmap &bitmap );
139 wxBitmap ConvertToBitmap() const;
140
141 void Create( int width, int height );
142 void Destroy();
143
144 wxImage Scale( int width, int height );
145
146 // these routines are slow but safe
147 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
148 unsigned char GetRed( int x, int y );
149 unsigned char GetGreen( int x, int y );
150 unsigned char GetBlue( int x, int y );
151
152 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
153
154 #if wxUSE_STREAMS
155 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
156 #endif
157
158 virtual bool SaveFile( const wxString& name, int type );
159
160 #if wxUSE_STREAMS
161 virtual bool SaveFile( wxOutputStream& stream, int type );
162 #endif
163
164 bool Ok() const;
165 int GetWidth() const;
166 int GetHeight() const;
167
168 char unsigned *GetData() const;
169 void SetData( char unsigned *data );
170
171 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
172 unsigned char GetMaskRed() const;
173 unsigned char GetMaskGreen() const;
174 unsigned char GetMaskBlue() const;
175 void SetMask( bool mask = TRUE );
176 bool HasMask() const;
177
178 inline wxImage& operator = (const wxImage& image)
179 { if ((*this) == image)
180 return (*this);
181 Ref(image);
182 return *this; }
183
184 inline bool operator == (const wxImage& image)
185 { return m_refData == image.m_refData; }
186 inline bool operator != (const wxImage& image)
187 { return m_refData != image.m_refData; }
188
189 static inline wxList& GetHandlers() { return sm_handlers; }
190 static void AddHandler( wxImageHandler *handler );
191 static void InsertHandler( wxImageHandler *handler );
192 static bool RemoveHandler( const wxString& name );
193 static wxImageHandler *FindHandler( const wxString& name );
194 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
195 static wxImageHandler *FindHandler( long imageType );
196
197 static void CleanUpHandlers();
198 static void InitStandardHandlers();
199
200 protected:
201
202 static wxList sm_handlers;
203
204 };
205
206 #endif
207 // _WX_IMAGE_H_