]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/bitmap.h
Add wxEventLoop::ScheduleExit().
[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 #ifdef __WXGTK3__
14 typedef struct _cairo cairo_t;
15 typedef struct _cairo_surface cairo_surface_t;
16 #endif
17 typedef struct _GdkPixbuf GdkPixbuf;
18 class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
19
20 //-----------------------------------------------------------------------------
21 // wxMask
22 //-----------------------------------------------------------------------------
23
24 class WXDLLIMPEXP_CORE wxMask: public wxMaskBase
25 {
26 public:
27 wxMask();
28 wxMask(const wxMask& mask);
29 wxMask( const wxBitmap& bitmap, const wxColour& colour );
30 #if wxUSE_PALETTE
31 wxMask( const wxBitmap& bitmap, int paletteIndex );
32 #endif // wxUSE_PALETTE
33 wxMask( const wxBitmap& bitmap );
34 virtual ~wxMask();
35 wxBitmap GetBitmap() const;
36
37 // implementation
38 #ifdef __WXGTK3__
39 wxMask(cairo_surface_t*);
40 operator cairo_surface_t*() const;
41 #else
42 wxMask(GdkPixmap*);
43 operator GdkPixmap*() const;
44 #endif
45
46 protected:
47 virtual void FreeData();
48 virtual bool InitFromColour(const wxBitmap& bitmap, const wxColour& colour);
49 virtual bool InitFromMonoBitmap(const wxBitmap& bitmap);
50
51 private:
52 #ifdef __WXGTK3__
53 cairo_surface_t* m_bitmap;
54 #else
55 GdkPixmap* m_bitmap;
56 #endif
57
58 DECLARE_DYNAMIC_CLASS(wxMask)
59 };
60
61 //-----------------------------------------------------------------------------
62 // wxBitmap
63 //-----------------------------------------------------------------------------
64
65 class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase
66 {
67 public:
68 wxBitmap() { }
69 wxBitmap( int width, int height, int depth = wxBITMAP_SCREEN_DEPTH )
70 { Create(width, height, depth); }
71 wxBitmap( const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH )
72 { Create(sz, depth); }
73 wxBitmap( const char bits[], int width, int height, int depth = 1 );
74 wxBitmap( const char* const* bits );
75 #ifdef wxNEEDS_CHARPP
76 // needed for old GCC
77 wxBitmap(char** data)
78 { *this = wxBitmap(const_cast<const char* const*>(data)); }
79 #endif
80 wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_DEFAULT_TYPE );
81 #if wxUSE_IMAGE
82 wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
83 #endif // wxUSE_IMAGE
84 wxBitmap(GdkPixbuf* pixbuf, int depth = 0);
85 virtual ~wxBitmap();
86
87 bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
88 bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
89 { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
90 bool Create(int width, int height, const wxDC& WXUNUSED(dc))
91 { return Create(width,height); }
92
93
94 virtual int GetHeight() const;
95 virtual int GetWidth() const;
96 virtual int GetDepth() const;
97
98 #if wxUSE_IMAGE
99 wxImage ConvertToImage() const;
100 #endif // wxUSE_IMAGE
101
102 // copies the contents and mask of the given (colour) icon to the bitmap
103 virtual bool CopyFromIcon(const wxIcon& icon);
104
105 wxMask *GetMask() const;
106 void SetMask( wxMask *mask );
107 wxBitmap GetMaskBitmap() const;
108
109 wxBitmap GetSubBitmap( const wxRect& rect ) const;
110
111 bool SaveFile(const wxString &name, wxBitmapType type,
112 const wxPalette *palette = NULL) const;
113 bool LoadFile(const wxString &name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
114
115 #if wxUSE_PALETTE
116 wxPalette *GetPalette() const;
117 void SetPalette(const wxPalette& palette);
118 wxPalette *GetColourMap() const { return GetPalette(); }
119 #endif // wxUSE_PALETTE
120
121 static void InitStandardHandlers();
122
123 // implementation
124 // --------------
125
126 void SetHeight( int height );
127 void SetWidth( int width );
128 void SetDepth( int depth );
129
130 #ifdef __WXGTK3__
131 GdkPixbuf* GetPixbufNoMask() const;
132 cairo_t* CairoCreate() const;
133 void Draw(cairo_t* cr, int x, int y, bool useMask = true, const wxColour* fg = NULL, const wxColour* bg = NULL) const;
134 void SetSourceSurface(cairo_t* cr, int x, int y, const wxColour* fg = NULL, const wxColour* bg = NULL) const;
135 #else
136 GdkPixmap *GetPixmap() const;
137 bool HasPixmap() const;
138 bool HasPixbuf() const;
139 wxBitmap(GdkPixmap* pixmap);
140 #endif
141 GdkPixbuf *GetPixbuf() const;
142
143 // raw bitmap access support functions
144 void *GetRawData(wxPixelDataBase& data, int bpp);
145 void UngetRawData(wxPixelDataBase& data);
146
147 bool HasAlpha() const;
148
149 protected:
150 #ifndef __WXGTK3__
151 #if wxUSE_IMAGE
152 bool CreateFromImage(const wxImage& image, int depth);
153 #endif // wxUSE_IMAGE
154 #endif
155
156 virtual wxGDIRefData* CreateGDIRefData() const;
157 virtual wxGDIRefData* CloneGDIRefData(const wxGDIRefData* data) const;
158
159 private:
160 #ifndef __WXGTK3__
161 void SetPixmap(GdkPixmap* pixmap);
162 #if wxUSE_IMAGE
163 // to be called from CreateFromImage only!
164 bool CreateFromImageAsPixmap(const wxImage& image, int depth);
165 bool CreateFromImageAsPixbuf(const wxImage& image);
166 #endif // wxUSE_IMAGE
167
168 public:
169 // implementation only
170 enum Representation
171 {
172 Pixmap,
173 Pixbuf
174 };
175 // removes other representations from memory, keeping only 'keep'
176 // (wxBitmap may keep same bitmap e.g. as both pixmap and pixbuf):
177 void PurgeOtherRepresentations(Representation keep);
178 #endif
179
180 DECLARE_DYNAMIC_CLASS(wxBitmap)
181 };
182
183 #endif // _WX_GTK_BITMAP_H_