1///////////////////////////////////////////////////////////////////////////// 2// Name: wx/msw/bitmap.h 3// Purpose: wxBitmap class 4// Author: Julian Smart 5// Modified by: 6// Created: 01/02/97 7// RCS-ID: $Id: bitmap.h 49563 2007-10-31 20:46:21Z VZ $ 8// Copyright: (c) Julian Smart 9// Licence: wxWindows licence 10///////////////////////////////////////////////////////////////////////////// 11 12#ifndef _WX_BITMAP_H_ 13#define _WX_BITMAP_H_ 14 15#include "wx/msw/gdiimage.h" 16#include "wx/palette.h" 17 18class WXDLLIMPEXP_FWD_CORE wxBitmap; 19class WXDLLIMPEXP_FWD_CORE wxBitmapHandler; 20class WXDLLIMPEXP_FWD_CORE wxBitmapRefData; 21class WXDLLIMPEXP_FWD_CORE wxControl; 22class WXDLLIMPEXP_FWD_CORE wxCursor; 23class WXDLLIMPEXP_FWD_CORE wxDC; 24#if wxUSE_WXDIB 25class WXDLLIMPEXP_FWD_CORE wxDIB; 26#endif 27class WXDLLIMPEXP_FWD_CORE wxIcon; 28class WXDLLIMPEXP_FWD_CORE wxImage; 29class WXDLLIMPEXP_FWD_CORE wxMask; 30class WXDLLIMPEXP_FWD_CORE wxPalette; 31class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; 32 33// ---------------------------------------------------------------------------- 34// wxBitmap: a mono or colour bitmap 35// ---------------------------------------------------------------------------- 36 37class WXDLLEXPORT wxBitmap : public wxGDIImage 38{ 39public: 40 // default ctor creates an invalid bitmap, you must Create() it later 41 wxBitmap() { } 42 43 // Initialize with raw data 44 wxBitmap(const char bits[], int width, int height, int depth = 1); 45 46 // Initialize with XPM data 47 wxBitmap(const char* const* data); 48#ifdef wxNEEDS_CHARPP 49 wxBitmap(char** data) 50 { 51 *this = wxBitmap(wx_const_cast(const char* const*, data)); 52 } 53#endif 54 55 // Load a file or resource 56 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE); 57 58 // New constructor for generalised creation from data 59 wxBitmap(const void* data, long type, int width, int height, int depth = 1); 60 61 // Create a new, uninitialized bitmap of the given size and depth (if it 62 // is omitted, will create a bitmap compatible with the display) 63 // 64 // NB: this ctor will create a DIB for 24 and 32bpp bitmaps, use ctor 65 // taking a DC argument if you want to force using DDB in this case 66 wxBitmap(int width, int height, int depth = -1); 67 68 // Create a bitmap compatible with the given DC 69 wxBitmap(int width, int height, const wxDC& dc); 70 71#if wxUSE_IMAGE 72 // Convert from wxImage 73 wxBitmap(const wxImage& image, int depth = -1) 74 { (void)CreateFromImage(image, depth); } 75 76 // Create a DDB compatible with the given DC from wxImage 77 wxBitmap(const wxImage& image, const wxDC& dc) 78 { (void)CreateFromImage(image, dc); } 79#endif // wxUSE_IMAGE 80 81 // we must have this, otherwise icons are silently copied into bitmaps using 82 // the copy ctor but the resulting bitmap is invalid! 83 wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); } 84 85 wxBitmap& operator=(const wxIcon& icon) 86 { 87 (void)CopyFromIcon(icon); 88 89 return *this; 90 } 91 92 wxBitmap& operator=(const wxCursor& cursor) 93 { 94 (void)CopyFromCursor(cursor); 95 96 return *this; 97 } 98 99 virtual ~wxBitmap(); 100 101#if wxUSE_IMAGE 102 wxImage ConvertToImage() const; 103#endif // wxUSE_IMAGE 104 105 // get the given part of bitmap 106 wxBitmap GetSubBitmap( const wxRect& rect ) const; 107 108 // NB: This should not be called from user code. It is for wx internal 109 // use only. 110 wxBitmap GetSubBitmapOfHDC( const wxRect& rect, WXHDC hdc ) const; 111 112 // copies the contents and mask of the given (colour) icon to the bitmap 113 bool CopyFromIcon(const wxIcon& icon); 114 115 // copies the contents and mask of the given cursor to the bitmap 116 bool CopyFromCursor(const wxCursor& cursor); 117 118#if wxUSE_WXDIB 119 // copies from a device independent bitmap 120 bool CopyFromDIB(const wxDIB& dib); 121#endif 122 123 virtual bool Create(int width, int height, int depth = -1); 124 virtual bool Create(int width, int height, const wxDC& dc); 125 virtual bool Create(const void* data, long type, int width, int height, int depth = 1); 126 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); 127 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); 128 129 wxBitmapRefData *GetBitmapData() const 130 { return (wxBitmapRefData *)m_refData; } 131 132 // raw bitmap access support functions 133 void *GetRawData(wxPixelDataBase& data, int bpp); 134 void UngetRawData(wxPixelDataBase& data); 135 136#if wxUSE_PALETTE 137 wxPalette* GetPalette() const; 138 void SetPalette(const wxPalette& palette); 139#endif // wxUSE_PALETTE 140 141 wxMask *GetMask() const; 142 wxBitmap GetMaskBitmap() const; 143 void SetMask(wxMask *mask); 144 145 // these functions are internal and shouldn't be used, they risk to 146 // disappear in the future 147 bool HasAlpha() const; 148 void UseAlpha(); 149 150#if WXWIN_COMPATIBILITY_2_4 151 // these functions do nothing and are only there for backwards 152 // compatibility 153 wxDEPRECATED( int GetQuality() const ); 154 wxDEPRECATED( void SetQuality(int quality) ); 155#endif // WXWIN_COMPATIBILITY_2_4 156 157 // implementation only from now on 158 // ------------------------------- 159 160public: 161 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); } 162 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); } 163 164#ifdef __WXDEBUG__ 165 void SetSelectedInto(wxDC *dc); 166 wxDC *GetSelectedInto() const; 167#endif // __WXDEBUG__ 168 169protected: 170 virtual wxGDIImageRefData *CreateData() const; 171 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; 172 173 // creates an uninitialized bitmap, called from Create()s above 174 bool DoCreate(int w, int h, int depth, WXHDC hdc); 175 176#if wxUSE_IMAGE 177 // creates the bitmap from wxImage, supposed to be called from ctor 178 bool CreateFromImage(const wxImage& image, int depth); 179 180 // creates a DDB from wxImage, supposed to be called from ctor 181 bool CreateFromImage(const wxImage& image, const wxDC& dc); 182 183 // common part of the 2 methods above (hdc may be 0) 184 bool CreateFromImage(const wxImage& image, int depth, WXHDC hdc); 185#endif // wxUSE_IMAGE 186 187private: 188 // common part of CopyFromIcon/CopyFromCursor for Win32 189 bool CopyFromIconOrCursor(const wxGDIImage& icon); 190 191 192 DECLARE_DYNAMIC_CLASS(wxBitmap) 193}; 194 195// ---------------------------------------------------------------------------- 196// wxMask: a mono bitmap used for drawing bitmaps transparently. 197// ---------------------------------------------------------------------------- 198 199class WXDLLEXPORT wxMask : public wxObject 200{ 201public: 202 wxMask(); 203 204 // Copy constructor 205 wxMask(const wxMask &mask); 206 207 // Construct a mask from a bitmap and a colour indicating the transparent 208 // area 209 wxMask(const wxBitmap& bitmap, const wxColour& colour); 210 211 // Construct a mask from a bitmap and a palette index indicating the 212 // transparent area 213 wxMask(const wxBitmap& bitmap, int paletteIndex); 214 215 // Construct a mask from a mono bitmap (copies the bitmap). 216 wxMask(const wxBitmap& bitmap); 217 218 // construct a mask from the givne bitmap handle 219 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; } 220 221 virtual ~wxMask(); 222 223 bool Create(const wxBitmap& bitmap, const wxColour& colour); 224 bool Create(const wxBitmap& bitmap, int paletteIndex); 225 bool Create(const wxBitmap& bitmap); 226 227 // Implementation 228 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } 229 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } 230 231protected: 232 WXHBITMAP m_maskBitmap; 233 234 DECLARE_DYNAMIC_CLASS(wxMask) 235}; 236 237// ---------------------------------------------------------------------------- 238// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file 239// ---------------------------------------------------------------------------- 240 241class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler 242{ 243public: 244 wxBitmapHandler() { } 245 wxBitmapHandler(const wxString& name, const wxString& ext, long type) 246 : wxGDIImageHandler(name, ext, type) 247 { 248 } 249 250 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the 251 // old class which worked only with bitmaps 252 virtual bool Create(wxBitmap *bitmap, 253 const void* data, 254 long flags, 255 int width, int height, int depth = 1); 256 virtual bool LoadFile(wxBitmap *bitmap, 257 const wxString& name, 258 long flags, 259 int desiredWidth, int desiredHeight); 260 virtual bool SaveFile(wxBitmap *bitmap, 261 const wxString& name, 262 int type, 263 const wxPalette *palette = NULL); 264 265 virtual bool Create(wxGDIImage *image, 266 const void* data, 267 long flags, 268 int width, int height, int depth = 1); 269 virtual bool Load(wxGDIImage *image, 270 const wxString& name, 271 long flags, 272 int desiredWidth, int desiredHeight); 273 virtual bool Save(wxGDIImage *image, 274 const wxString& name, 275 int type); 276 277private: 278 DECLARE_DYNAMIC_CLASS(wxBitmapHandler) 279}; 280 281#endif 282 // _WX_BITMAP_H_ 283