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