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