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