1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/bitmap.h
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __GTKBITMAPH__
12 #define __GTKBITMAPH__
15 #include "wx/object.h"
16 #include "wx/string.h"
17 #include "wx/palette.h"
18 #include "wx/gdiobj.h"
20 typedef struct _GdkPixbuf GdkPixbuf
;
22 class WXDLLEXPORT wxPixelDataBase
;
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 class WXDLLIMPEXP_CORE wxMask
;
29 class WXDLLIMPEXP_CORE wxBitmap
;
30 class WXDLLIMPEXP_CORE wxImage
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 class WXDLLIMPEXP_CORE wxMask
: public wxObject
40 wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
);
42 wxMask( const wxBitmap
& bitmap
, int paletteIndex
);
43 #endif // wxUSE_PALETTE
44 wxMask( const wxBitmap
& bitmap
);
47 bool Create( const wxBitmap
& bitmap
, const wxColour
& colour
);
49 bool Create( const wxBitmap
& bitmap
, int paletteIndex
);
50 #endif // wxUSE_PALETTE
51 bool Create( const wxBitmap
& bitmap
);
56 GdkBitmap
*GetBitmap() const;
59 DECLARE_DYNAMIC_CLASS(wxMask
)
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 class WXDLLIMPEXP_CORE wxBitmap
: public wxBitmapBase
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 wxBitmap
& bmp
);
75 wxBitmap( const wxString
&filename
, wxBitmapType type
= wxBITMAP_TYPE_XPM
);
76 wxBitmap( const wxImage
& image
, int depth
= -1 ) { (void)CreateFromImage(image
, depth
); }
78 wxBitmap
& operator = ( const wxBitmap
& bmp
);
79 bool operator == ( const wxBitmap
& bmp
) const;
80 bool operator != ( const wxBitmap
& bmp
) const;
83 bool Create(int width
, int height
, int depth
= -1);
85 int GetHeight() const;
89 wxImage
ConvertToImage() const;
91 // copies the contents and mask of the given (colour) icon to the bitmap
92 virtual bool CopyFromIcon(const wxIcon
& icon
);
94 wxMask
*GetMask() const;
95 void SetMask( wxMask
*mask
);
97 wxBitmap
GetSubBitmap( const wxRect
& rect
) const;
99 bool SaveFile(const wxString
&name
, wxBitmapType type
,
100 const wxPalette
*palette
= (wxPalette
*)NULL
) const;
101 bool LoadFile(const wxString
&name
, wxBitmapType type
= wxBITMAP_TYPE_XPM
);
104 wxPalette
*GetPalette() const;
105 void SetPalette(const wxPalette
& palette
);
106 wxPalette
*GetColourMap() const { return GetPalette(); };
107 #endif // wxUSE_PALETTE
109 static void InitStandardHandlers();
114 void SetHeight( int height
);
115 void SetWidth( int width
);
116 void SetDepth( int depth
);
117 void SetPixmap( GdkPixmap
*pixmap
);
118 void SetBitmap( GdkBitmap
*bitmap
);
119 void SetPixbuf(GdkPixbuf
*pixbuf
);
121 GdkPixmap
*GetPixmap() const;
122 GdkBitmap
*GetBitmap() const;
123 bool HasPixmap() const;
124 bool HasPixbuf() const;
125 GdkPixbuf
*GetPixbuf() const;
127 // Basically, this corresponds to Win32 StretchBlt()
128 wxBitmap
Rescale( int clipx
, int clipy
, int clipwidth
, int clipheight
, int width
, int height
);
130 // raw bitmap access support functions
131 void *GetRawData(wxPixelDataBase
& data
, int bpp
);
132 void UngetRawData(wxPixelDataBase
& data
);
134 bool HasAlpha() const;
138 bool CreateFromXpm(const char **bits
);
139 bool CreateFromImage(const wxImage
& image
, int depth
);
142 // to be called from CreateFromImage only!
143 bool CreateFromImageAsBitmap(const wxImage
& image
);
144 bool CreateFromImageAsPixmap(const wxImage
& image
);
146 bool CreateFromImageAsPixbuf(const wxImage
& image
);
153 // removes other representations from memory, keeping only 'keep'
154 // (wxBitmap may keep same bitmap e.g. as both pixmap and pixbuf):
155 void PurgeOtherRepresentations(Representation keep
);
157 friend class wxMemoryDC
;
158 friend class wxBitmapHandler
;
161 DECLARE_DYNAMIC_CLASS(wxBitmap
)
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
168 class WXDLLIMPEXP_CORE wxBitmapHandler
: public wxBitmapHandlerBase
171 wxBitmapHandler() { }
172 virtual ~wxBitmapHandler();
174 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
175 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
176 int desiredWidth
, int desiredHeight
);
177 virtual bool SaveFile(const wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
180 DECLARE_DYNAMIC_CLASS(wxBitmapHandler
)
184 #endif // __GTKBITMAPH__