]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
set m_clipXX so dc.GetClippingBox returns real bounding box
[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
4fe5383d 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_BITMAP_H_
13#define _WX_BITMAP_H_
2bda0e17
KB
14
15#ifdef __GNUG__
4fe5383d 16 #pragma interface "bitmap.h"
2bda0e17
KB
17#endif
18
6d167489 19#include "wx/msw/gdiimage.h"
2bda0e17
KB
20#include "wx/gdicmn.h"
21#include "wx/palette.h"
22
2bda0e17
KB
23class WXDLLEXPORT wxDC;
24class WXDLLEXPORT wxControl;
25class WXDLLEXPORT wxBitmap;
26class WXDLLEXPORT wxBitmapHandler;
27class WXDLLEXPORT wxIcon;
6d167489 28class WXDLLEXPORT wxMask;
2bda0e17 29class WXDLLEXPORT wxCursor;
03ab016d 30class WXDLLEXPORT wxControl;
2bda0e17 31
6d167489
VZ
32// ----------------------------------------------------------------------------
33// Bitmap data
34//
35// NB: this class is private, but declared here to make it possible inline
36// wxBitmap functions accessing it
37// ----------------------------------------------------------------------------
4fe5383d 38
6d167489 39class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
2bda0e17 40{
2bda0e17 41public:
10fcf31a 42 wxBitmapRefData();
6d167489
VZ
43 virtual ~wxBitmapRefData() { Free(); }
44
45 virtual void Free();
2bda0e17
KB
46
47public:
6d167489
VZ
48 int m_numColors;
49 wxPalette m_bitmapPalette;
50 int m_quality;
2bda0e17 51
6d167489
VZ
52 // MSW-specific
53 // ------------
2bda0e17 54
6d167489
VZ
55 // this field is solely for error checking: we detect selecting a bitmap
56 // into more than one DC at once or deleting a bitmap still selected into a
57 // DC (both are serious programming errors under Windows)
58 wxDC *m_selectedInto;
59
60 // optional mask for transparent drawing
61 wxMask *m_bitmapMask;
2bda0e17 62};
2bda0e17 63
6d167489
VZ
64// ----------------------------------------------------------------------------
65// wxBitmap: a mono or colour bitmap
66// ----------------------------------------------------------------------------
2bda0e17 67
6d167489
VZ
68class WXDLLEXPORT wxBitmap : public wxGDIImage
69{
2bda0e17 70public:
4fe5383d
VZ
71 // default ctor creates an invalid bitmap, you must Create() it later
72 wxBitmap() { Init(); }
73
74 // Copy constructors
75 wxBitmap(const wxBitmap& bitmap) { Init(); Ref(bitmap); }
76
77 // Initialize with raw data
78 wxBitmap(const char bits[], int width, int height, int depth = 1);
79
80 // Initialize with XPM data
4b7f2165
VZ
81 wxBitmap(const char **data) { CreateFromXpm(data); }
82 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
2bda0e17 83
4fe5383d
VZ
84 // Load a file or resource
85 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17 86
4fe5383d
VZ
87 // New constructor for generalised creation from data
88 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17 89
4fe5383d
VZ
90 // If depth is omitted, will create a bitmap compatible with the display
91 wxBitmap(int width, int height, int depth = -1);
2bda0e17 92
4fe5383d
VZ
93 // we must have this, otherwise icons are silently copied into bitmaps using
94 // the copy ctor but the resulting bitmap is invalid!
95 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
2bda0e17 96
4fe5383d
VZ
97 wxBitmap& operator=(const wxBitmap& bitmap)
98 {
99 if ( m_refData != bitmap.m_refData )
100 Ref(bitmap);
101 return *this;
102 }
2bda0e17 103
4fe5383d
VZ
104 wxBitmap& operator=(const wxIcon& icon)
105 {
106 (void)CopyFromIcon(icon);
07cf98cb 107
4fe5383d
VZ
108 return *this;
109 }
07cf98cb 110
6d167489
VZ
111 wxBitmap& operator=(const wxCursor& cursor)
112 {
113 (void)CopyFromCursor(cursor);
114
115 return *this;
116 }
117
4fe5383d 118 virtual ~wxBitmap();
2bda0e17 119
4b7f2165 120 // get the given part of bitmap
8208e181 121 wxBitmap GetSubBitmap( const wxRect& rect ) const;
3f399a69 122
4fe5383d
VZ
123 // copies the contents and mask of the given (colour) icon to the bitmap
124 bool CopyFromIcon(const wxIcon& icon);
2bda0e17 125
6d167489
VZ
126 // copies the contents and mask of the given cursor to the bitmap
127 bool CopyFromCursor(const wxCursor& cursor);
128
4fe5383d
VZ
129 virtual bool Create(int width, int height, int depth = -1);
130 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
131 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
132 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
133
6d167489
VZ
134 wxBitmapRefData *GetBitmapData() const { return (wxBitmapRefData *)m_refData; }
135
136 int GetQuality() const { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); }
4fe5383d 137 void SetQuality(int q);
6d167489
VZ
138
139 wxPalette* GetPalette() const { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); }
4fe5383d 140 void SetPalette(const wxPalette& palette);
2bda0e17 141
6d167489 142 wxMask *GetMask() const { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); }
4fe5383d 143 void SetMask(wxMask *mask) ;
2bda0e17 144
4fe5383d
VZ
145 bool operator==(const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
146 bool operator!=(const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
ce3ed50d 147
6d167489
VZ
148#if WXWIN_COMPATIBILITY_2
149 void SetOk(bool isOk);
150#endif // WXWIN_COMPATIBILITY_2
2bda0e17 151
6d167489
VZ
152#if WXWIN_COMPATIBILITY
153 wxPalette *GetColourMap() const { return GetPalette(); }
154 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
155#endif // WXWIN_COMPATIBILITY
2bda0e17 156
4fe5383d 157 // Implementation
2bda0e17 158public:
6d167489
VZ
159 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
160 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
161
162 void SetSelectedInto(wxDC *dc) { if (GetBitmapData()) GetBitmapData()->m_selectedInto = dc; }
163 wxDC *GetSelectedInto() const { return (GetBitmapData() ? GetBitmapData()->m_selectedInto : (wxDC*) NULL); }
164
165 // Creates a bitmap that matches the device context's depth, from an
166 // arbitray bitmap. At present, the original bitmap must have an associated
167 // palette. (TODO: use a default palette if no palette exists.) This
168 // function is necessary for you to Blit an arbitrary bitmap (which may
169 // have the wrong depth). wxDC::SelectObject will compare the depth of the
170 // bitmap with the DC's depth, and create a new bitmap if the depths
171 // differ. Eventually we should perhaps make this a public API function so
172 // that an app can efficiently produce bitmaps of the correct depth. The
173 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
174 // to a DC, but this is too Windows-specific, hence this solution of
175 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
176 // <frederic.villeneuve@natinst.com>
4fe5383d
VZ
177 wxBitmap GetBitmapForDC(wxDC& dc) const;
178
179protected:
180 // common part of all ctors
181 void Init();
7b46ecac 182
6d167489
VZ
183 virtual wxGDIImageRefData *CreateData() const
184 { return new wxBitmapRefData; }
185
4b7f2165
VZ
186 // creates the bitmap from XPM data, supposed to be called from ctor
187 bool CreateFromXpm(const char **bits);
188
4fe5383d 189private:
6d167489
VZ
190#ifdef __WIN32__
191 // common part of CopyFromIcon/CopyFromCursor for Win32
192 bool CopyFromIconOrCursor(const wxGDIImage& icon);
193#endif // __WIN32__
194
4fe5383d 195 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 196};
ce3ed50d 197
6d167489
VZ
198// ----------------------------------------------------------------------------
199// wxMask: a mono bitmap used for drawing bitmaps transparently.
200// ----------------------------------------------------------------------------
201
202class WXDLLEXPORT wxMask : public wxObject
203{
204public:
205 wxMask();
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() { m_type = wxBITMAP_TYPE_INVALID; }
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 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 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
2bda0e17 281#endif
bbcdf8bc 282 // _WX_BITMAP_H_