]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
Applied patch [ 597398 ] Generic MDI, wxNotebook based.
[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;
fd859211 31class WXDLLEXPORT wxImage;
d275c7eb 32class WXDLLEXPORT wxPalette;
2bda0e17 33
6d167489
VZ
34// ----------------------------------------------------------------------------
35// Bitmap data
36//
37// NB: this class is private, but declared here to make it possible inline
38// wxBitmap functions accessing it
39// ----------------------------------------------------------------------------
4fe5383d 40
6d167489 41class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
2bda0e17 42{
2bda0e17 43public:
10fcf31a 44 wxBitmapRefData();
6d167489
VZ
45 virtual ~wxBitmapRefData() { Free(); }
46
47 virtual void Free();
2bda0e17
KB
48
49public:
6d167489 50 int m_numColors;
d275c7eb 51#if wxUSE_PALETTE
6d167489 52 wxPalette m_bitmapPalette;
d275c7eb 53#endif // wxUSE_PALETTE
6d167489 54 int m_quality;
2bda0e17 55
6d167489
VZ
56 // MSW-specific
57 // ------------
2bda0e17 58
6d167489
VZ
59 // this field is solely for error checking: we detect selecting a bitmap
60 // into more than one DC at once or deleting a bitmap still selected into a
61 // DC (both are serious programming errors under Windows)
62 wxDC *m_selectedInto;
63
64 // optional mask for transparent drawing
65 wxMask *m_bitmapMask;
2bda0e17 66};
2bda0e17 67
6d167489
VZ
68// ----------------------------------------------------------------------------
69// wxBitmap: a mono or colour bitmap
70// ----------------------------------------------------------------------------
2bda0e17 71
6d167489
VZ
72class WXDLLEXPORT wxBitmap : public wxGDIImage
73{
2bda0e17 74public:
4fe5383d
VZ
75 // default ctor creates an invalid bitmap, you must Create() it later
76 wxBitmap() { Init(); }
77
78 // Copy constructors
79 wxBitmap(const wxBitmap& bitmap) { Init(); Ref(bitmap); }
80
81 // Initialize with raw data
82 wxBitmap(const char bits[], int width, int height, int depth = 1);
83
84 // Initialize with XPM data
4b7f2165
VZ
85 wxBitmap(const char **data) { CreateFromXpm(data); }
86 wxBitmap(char **data) { CreateFromXpm((const char **)data); }
2bda0e17 87
4fe5383d 88 // Load a file or resource
2aeec9ec 89 wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17 90
4fe5383d
VZ
91 // New constructor for generalised creation from data
92 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17 93
4fe5383d
VZ
94 // If depth is omitted, will create a bitmap compatible with the display
95 wxBitmap(int width, int height, int depth = -1);
6d51f220
VZ
96
97#if wxUSE_IMAGE
fd859211 98 // Convert from wxImage:
6d51f220
VZ
99 wxBitmap(const wxImage& image, int depth = -1)
100 { (void)CreateFromImage(image, depth); }
101#endif // wxUSE_IMAGE
2bda0e17 102
4fe5383d
VZ
103 // we must have this, otherwise icons are silently copied into bitmaps using
104 // the copy ctor but the resulting bitmap is invalid!
105 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
2bda0e17 106
4fe5383d
VZ
107 wxBitmap& operator=(const wxBitmap& bitmap)
108 {
109 if ( m_refData != bitmap.m_refData )
110 Ref(bitmap);
111 return *this;
112 }
2bda0e17 113
4fe5383d
VZ
114 wxBitmap& operator=(const wxIcon& icon)
115 {
116 (void)CopyFromIcon(icon);
07cf98cb 117
4fe5383d
VZ
118 return *this;
119 }
07cf98cb 120
6d167489
VZ
121 wxBitmap& operator=(const wxCursor& cursor)
122 {
123 (void)CopyFromCursor(cursor);
124
125 return *this;
126 }
127
4fe5383d 128 virtual ~wxBitmap();
2bda0e17 129
6d51f220 130#if wxUSE_IMAGE
fd859211 131 wxImage ConvertToImage() const;
6d51f220 132#endif // wxUSE_IMAGE
fd859211 133
4b7f2165 134 // get the given part of bitmap
8208e181 135 wxBitmap GetSubBitmap( const wxRect& rect ) const;
6d51f220 136
4fe5383d
VZ
137 // copies the contents and mask of the given (colour) icon to the bitmap
138 bool CopyFromIcon(const wxIcon& icon);
2bda0e17 139
6d167489
VZ
140 // copies the contents and mask of the given cursor to the bitmap
141 bool CopyFromCursor(const wxCursor& cursor);
142
4fe5383d
VZ
143 virtual bool Create(int width, int height, int depth = -1);
144 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
145 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
146 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
147
6d167489
VZ
148 wxBitmapRefData *GetBitmapData() const { return (wxBitmapRefData *)m_refData; }
149
150 int GetQuality() const { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); }
4fe5383d 151 void SetQuality(int q);
6d167489 152
d275c7eb 153#if wxUSE_PALETTE
6d167489 154 wxPalette* GetPalette() const { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); }
4fe5383d 155 void SetPalette(const wxPalette& palette);
d275c7eb 156#endif // wxUSE_PALETTE
2bda0e17 157
6d167489 158 wxMask *GetMask() const { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); }
4fe5383d 159 void SetMask(wxMask *mask) ;
2bda0e17 160
f6bcfd97
BP
161 bool operator==(const wxBitmap& bitmap) const { return m_refData == bitmap.m_refData; }
162 bool operator!=(const wxBitmap& bitmap) const { return m_refData != bitmap.m_refData; }
ce3ed50d 163
6d167489
VZ
164#if WXWIN_COMPATIBILITY_2
165 void SetOk(bool isOk);
166#endif // WXWIN_COMPATIBILITY_2
2bda0e17 167
d275c7eb 168#if wxUSE_PALETTE
6d167489
VZ
169#if WXWIN_COMPATIBILITY
170 wxPalette *GetColourMap() const { return GetPalette(); }
171 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
172#endif // WXWIN_COMPATIBILITY
d275c7eb 173#endif // wxUSE_PALETTE
2bda0e17 174
4fe5383d 175 // Implementation
2bda0e17 176public:
6d167489
VZ
177 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
178 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
179
180 void SetSelectedInto(wxDC *dc) { if (GetBitmapData()) GetBitmapData()->m_selectedInto = dc; }
181 wxDC *GetSelectedInto() const { return (GetBitmapData() ? GetBitmapData()->m_selectedInto : (wxDC*) NULL); }
182
183 // Creates a bitmap that matches the device context's depth, from an
184 // arbitray bitmap. At present, the original bitmap must have an associated
185 // palette. (TODO: use a default palette if no palette exists.) This
186 // function is necessary for you to Blit an arbitrary bitmap (which may
187 // have the wrong depth). wxDC::SelectObject will compare the depth of the
188 // bitmap with the DC's depth, and create a new bitmap if the depths
189 // differ. Eventually we should perhaps make this a public API function so
190 // that an app can efficiently produce bitmaps of the correct depth. The
191 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
192 // to a DC, but this is too Windows-specific, hence this solution of
193 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
194 // <frederic.villeneuve@natinst.com>
4fe5383d
VZ
195 wxBitmap GetBitmapForDC(wxDC& dc) const;
196
197protected:
198 // common part of all ctors
199 void Init();
7b46ecac 200
6d167489
VZ
201 virtual wxGDIImageRefData *CreateData() const
202 { return new wxBitmapRefData; }
203
4b7f2165
VZ
204 // creates the bitmap from XPM data, supposed to be called from ctor
205 bool CreateFromXpm(const char **bits);
6d51f220
VZ
206
207#if wxUSE_IMAGE
fd859211
VS
208 // creates the bitmap from wxImage, supposed to be called from ctor
209 bool CreateFromImage(const wxImage& image, int depth);
6d51f220 210#endif // wxUSE_IMAGE
4b7f2165 211
4fe5383d 212private:
6d167489
VZ
213#ifdef __WIN32__
214 // common part of CopyFromIcon/CopyFromCursor for Win32
215 bool CopyFromIconOrCursor(const wxGDIImage& icon);
216#endif // __WIN32__
217
4fe5383d 218 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 219};
ce3ed50d 220
6d167489
VZ
221// ----------------------------------------------------------------------------
222// wxMask: a mono bitmap used for drawing bitmaps transparently.
223// ----------------------------------------------------------------------------
224
225class WXDLLEXPORT wxMask : public wxObject
226{
227public:
228 wxMask();
229
230 // Construct a mask from a bitmap and a colour indicating the transparent
231 // area
232 wxMask(const wxBitmap& bitmap, const wxColour& colour);
233
234 // Construct a mask from a bitmap and a palette index indicating the
235 // transparent area
236 wxMask(const wxBitmap& bitmap, int paletteIndex);
237
238 // Construct a mask from a mono bitmap (copies the bitmap).
239 wxMask(const wxBitmap& bitmap);
240
241 // construct a mask from the givne bitmap handle
242 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
243
244 virtual ~wxMask();
245
246 bool Create(const wxBitmap& bitmap, const wxColour& colour);
247 bool Create(const wxBitmap& bitmap, int paletteIndex);
248 bool Create(const wxBitmap& bitmap);
249
250 // Implementation
251 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
252 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
253
254protected:
255 WXHBITMAP m_maskBitmap;
256
257 DECLARE_DYNAMIC_CLASS(wxMask)
258};
259
260// ----------------------------------------------------------------------------
261// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
262// ----------------------------------------------------------------------------
263
264class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
265{
266public:
267 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
268 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
269 : wxGDIImageHandler(name, ext, type)
270 {
271 }
272
273 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
274 // old class which worked only with bitmaps
275 virtual bool Create(wxBitmap *bitmap,
276 void *data,
277 long flags,
278 int width, int height, int depth = 1);
279 virtual bool LoadFile(wxBitmap *bitmap,
280 const wxString& name,
281 long flags,
282 int desiredWidth, int desiredHeight);
283 virtual bool SaveFile(wxBitmap *bitmap,
284 const wxString& name,
285 int type,
286 const wxPalette *palette = NULL);
287
288 virtual bool Create(wxGDIImage *image,
289 void *data,
290 long flags,
291 int width, int height, int depth = 1);
292 virtual bool Load(wxGDIImage *image,
293 const wxString& name,
294 long flags,
295 int desiredWidth, int desiredHeight);
296 virtual bool Save(wxGDIImage *image,
297 const wxString& name,
298 int type);
299
300private:
301 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
302};
303
2bda0e17 304#endif
bbcdf8bc 305 // _WX_BITMAP_H_