1///////////////////////////////////////////////////////////////////////////// 2// Name: bitmap.h 3// Purpose: wxBitmap class 4// Author: Stefan Csomor 5// Modified by: 6// Created: 1998-01-01 7// RCS-ID: $Id: bitmap.h 42752 2006-10-30 19:26:48Z VZ $ 8// Copyright: (c) Stefan Csomor 9// Licence: wxWindows licence 10///////////////////////////////////////////////////////////////////////////// 11 12#ifndef _WX_BITMAP_H_ 13#define _WX_BITMAP_H_ 14 15#include "wx/palette.h" 16 17// Bitmap 18class WXDLLEXPORT wxBitmap; 19class WXDLLEXPORT wxBitmapHandler; 20class WXDLLEXPORT wxControl; 21class WXDLLEXPORT wxCursor; 22class WXDLLEXPORT wxDC; 23class WXDLLEXPORT wxIcon; 24class WXDLLEXPORT wxImage; 25class WXDLLEXPORT wxPixelDataBase; 26 27// A mask is a bitmap used for drawing bitmaps 28// it can be a monochrome bitmap or a multi-bit bitmap which transfers to alpha channels 29// transparently. 30class WXDLLEXPORT wxMask: public wxObject 31{ 32 DECLARE_DYNAMIC_CLASS(wxMask) 33 DECLARE_NO_COPY_CLASS(wxMask) 34 35public: 36 wxMask(); 37 38 // Construct a mask from a bitmap and a colour indicating 39 // the transparent area 40 wxMask(const wxBitmap& bitmap, const wxColour& colour); 41 42 // Construct a mask from a bitmap and a palette index indicating 43 // the transparent area 44 wxMask(const wxBitmap& bitmap, int paletteIndex); 45 46 // Construct a mask from a mono bitmap (copies the bitmap). 47 wxMask(const wxBitmap& bitmap); 48 49 virtual ~wxMask(); 50 51 bool Create(const wxBitmap& bitmap, const wxColour& colour); 52 bool Create(const wxBitmap& bitmap, int paletteIndex); 53 bool Create(const wxBitmap& bitmap); 54 55 // Implementation 56 bool PointMasked(int x, int y); 57 inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } 58 inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } 59 int GetDepth() const { return m_depth ; } 60 void SetDepth( int depth ) { m_depth = depth ; } 61protected: 62 WXHBITMAP m_maskBitmap; 63 int m_depth ; 64}; 65 66enum { kMacBitmapTypeUnknownType , kMacBitmapTypeGrafWorld, kMacBitmapTypePict , kMacBitmapTypeIcon } ; 67 68class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData 69{ 70 DECLARE_NO_COPY_CLASS(wxBitmapRefData) 71 72 friend class WXDLLEXPORT wxBitmap; 73 friend class WXDLLEXPORT wxIcon; 74 friend class WXDLLEXPORT wxCursor; 75public: 76 wxBitmapRefData(); 77 virtual ~wxBitmapRefData(); 78 79public: 80 int m_width; 81 int m_height; 82 int m_depth; 83 bool m_ok; 84 int m_numColors; 85#if wxUSE_PALETTE 86 wxPalette m_bitmapPalette; 87#endif // wxUSE_PALETTE 88 int m_quality; 89 90 int m_bitmapType ; 91 WXHMETAFILE m_hPict ; 92 WXHBITMAP m_hBitmap; 93 WXHICON m_hIcon ; 94 wxMask * m_bitmapMask; // Optional mask 95 bool m_hasAlpha; 96}; 97 98#define M_BITMAPDATA ((wxBitmapRefData *)m_refData) 99 100class WXDLLEXPORT wxBitmapHandler: public wxBitmapHandlerBase 101{ 102 DECLARE_DYNAMIC_CLASS(wxBitmapHandler) 103public: 104 wxBitmapHandler() : m_name(), m_extension(), m_type(0) { } 105 virtual ~wxBitmapHandler(); 106 107 virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1); 108 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags, 109 int desiredWidth, int desiredHeight); 110 virtual bool SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL); 111 112 void SetName(const wxString& name) { m_name = name; } 113 void SetExtension(const wxString& ext) { m_extension = ext; } 114 void SetType(long type) { m_type = type; } 115 wxString GetName() const { return m_name; } 116 wxString GetExtension() const { return m_extension; } 117 long GetType() const { return m_type; } 118 119protected: 120 wxString m_name; 121 wxString m_extension; 122 long m_type; 123}; 124 125#define M_BITMAPHANDLERDATA ((wxBitmapRefData *)bitmap->GetRefData()) 126 127class WXDLLEXPORT wxBitmap: public wxBitmapBase 128{ 129 DECLARE_DYNAMIC_CLASS(wxBitmap) 130 131 friend class WXDLLEXPORT wxBitmapHandler; 132 133public: 134 wxBitmap(); // Platform-specific 135 136 // Initialize with raw data. 137 wxBitmap(const char bits[], int width, int height, int depth = 1); 138 139 // Initialize with XPM data 140 bool CreateFromXpm(const char **bits); 141 wxBitmap(const char **bits); 142 wxBitmap(char **bits); 143 144 // Load a file or resource 145 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_PICT_RESOURCE); 146 147 // Constructor for generalised creation from data 148 wxBitmap(void *data, wxBitmapType type, int width, int height, int depth = 1); 149 150 // If depth is omitted, will create a bitmap compatible with the display 151 wxBitmap(int width, int height, int depth = -1); 152 153 // Convert from wxImage: 154 wxBitmap(const wxImage& image, int depth = -1); 155 156 virtual ~wxBitmap(); 157 158 wxImage ConvertToImage() const; 159 160 // get the given part of bitmap 161 wxBitmap GetSubBitmap( const wxRect& rect ) const; 162 163 virtual bool Create(int width, int height, int depth = -1); 164 virtual bool Create(void *data, wxBitmapType type, int width, int height, int depth = 1); 165 virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); 166 virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const; 167 168 // copies the contents and mask of the given (colour) icon to the bitmap 169 virtual bool CopyFromIcon(const wxIcon& icon); 170 171 bool Ok() const { return IsOk(); } 172 bool IsOk() const; 173 int GetWidth() const; 174 int GetHeight() const; 175 int GetDepth() const; 176 int GetQuality() const; 177 void SetWidth(int w); 178 void SetHeight(int h); 179 void SetDepth(int d); 180 void SetQuality(int q); 181 void SetOk(bool isOk); 182 183#if wxUSE_PALETTE 184 wxPalette* GetPalette() const; 185 void SetPalette(const wxPalette& palette); 186#endif // wxUSE_PALETTE 187 188 wxMask *GetMask() const; 189 void SetMask(wxMask *mask) ; 190 191 int GetBitmapType() const; 192 193 static void InitStandardHandlers(); 194 195 // raw bitmap access support functions, for internal use only 196 void *GetRawData(wxPixelDataBase& data, int bpp); 197 void UngetRawData(wxPixelDataBase& data); 198 199 void UseAlpha(); 200 201public: 202 WXHBITMAP GetHBITMAP() const; 203 inline WXHICON GetHICON() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hIcon : 0); } 204 WXHMETAFILE GetPict(bool *created = NULL ) const; 205 206 void SetHBITMAP(WXHBITMAP bmp); 207 void SetHICON(WXHICON ico); 208 void SetPict( WXHMETAFILE pict ) ; 209 210 bool FreeResource(bool force = FALSE); 211}; 212#endif 213 // _WX_BITMAP_H_ 214