]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/bitmap.h
added wxUSE_TOOLBAR_SIMPLE setting, enabled wxLongLong in configure by default
[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
81 wxBitmap(char **data, wxControl *anItem = NULL);
2bda0e17 82
4fe5383d
VZ
83 // Load a file or resource
84 wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
2bda0e17 85
4fe5383d
VZ
86 // New constructor for generalised creation from data
87 wxBitmap(void *data, long type, int width, int height, int depth = 1);
2bda0e17 88
4fe5383d
VZ
89 // If depth is omitted, will create a bitmap compatible with the display
90 wxBitmap(int width, int height, int depth = -1);
2bda0e17 91
4fe5383d
VZ
92 // we must have this, otherwise icons are silently copied into bitmaps using
93 // the copy ctor but the resulting bitmap is invalid!
94 wxBitmap(const wxIcon& icon) { Init(); CopyFromIcon(icon); }
2bda0e17 95
4fe5383d
VZ
96 wxBitmap& operator=(const wxBitmap& bitmap)
97 {
98 if ( m_refData != bitmap.m_refData )
99 Ref(bitmap);
100 return *this;
101 }
2bda0e17 102
4fe5383d
VZ
103 wxBitmap& operator=(const wxIcon& icon)
104 {
105 (void)CopyFromIcon(icon);
07cf98cb 106
4fe5383d
VZ
107 return *this;
108 }
07cf98cb 109
6d167489
VZ
110 wxBitmap& operator=(const wxCursor& cursor)
111 {
112 (void)CopyFromCursor(cursor);
113
114 return *this;
115 }
116
4fe5383d 117 virtual ~wxBitmap();
2bda0e17 118
4fe5383d
VZ
119 // copies the contents and mask of the given (colour) icon to the bitmap
120 bool CopyFromIcon(const wxIcon& icon);
2bda0e17 121
6d167489
VZ
122 // copies the contents and mask of the given cursor to the bitmap
123 bool CopyFromCursor(const wxCursor& cursor);
124
4fe5383d
VZ
125 virtual bool Create(int width, int height, int depth = -1);
126 virtual bool Create(void *data, long type, int width, int height, int depth = 1);
127 virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE);
128 virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL);
129
6d167489
VZ
130 wxBitmapRefData *GetBitmapData() const { return (wxBitmapRefData *)m_refData; }
131
132 int GetQuality() const { return (GetBitmapData() ? GetBitmapData()->m_quality : 0); }
4fe5383d 133 void SetQuality(int q);
6d167489
VZ
134
135 wxPalette* GetPalette() const { return (GetBitmapData() ? (& GetBitmapData()->m_bitmapPalette) : (wxPalette*) NULL); }
4fe5383d 136 void SetPalette(const wxPalette& palette);
2bda0e17 137
6d167489 138 wxMask *GetMask() const { return (GetBitmapData() ? GetBitmapData()->m_bitmapMask : (wxMask*) NULL); }
4fe5383d 139 void SetMask(wxMask *mask) ;
2bda0e17 140
4fe5383d
VZ
141 bool operator==(const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; }
142 bool operator!=(const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; }
ce3ed50d 143
6d167489
VZ
144#if WXWIN_COMPATIBILITY_2
145 void SetOk(bool isOk);
146#endif // WXWIN_COMPATIBILITY_2
2bda0e17 147
6d167489
VZ
148#if WXWIN_COMPATIBILITY
149 wxPalette *GetColourMap() const { return GetPalette(); }
150 void SetColourMap(wxPalette *cmap) { SetPalette(*cmap); };
151#endif // WXWIN_COMPATIBILITY
2bda0e17 152
4fe5383d 153 // Implementation
2bda0e17 154public:
6d167489
VZ
155 void SetHBITMAP(WXHBITMAP bmp) { SetHandle((WXHANDLE)bmp); }
156 WXHBITMAP GetHBITMAP() const { return (WXHBITMAP)GetHandle(); }
157
158 void SetSelectedInto(wxDC *dc) { if (GetBitmapData()) GetBitmapData()->m_selectedInto = dc; }
159 wxDC *GetSelectedInto() const { return (GetBitmapData() ? GetBitmapData()->m_selectedInto : (wxDC*) NULL); }
160
161 // Creates a bitmap that matches the device context's depth, from an
162 // arbitray bitmap. At present, the original bitmap must have an associated
163 // palette. (TODO: use a default palette if no palette exists.) This
164 // function is necessary for you to Blit an arbitrary bitmap (which may
165 // have the wrong depth). wxDC::SelectObject will compare the depth of the
166 // bitmap with the DC's depth, and create a new bitmap if the depths
167 // differ. Eventually we should perhaps make this a public API function so
168 // that an app can efficiently produce bitmaps of the correct depth. The
169 // Windows solution is to use SetDibBits to blit an arbotrary DIB directly
170 // to a DC, but this is too Windows-specific, hence this solution of
171 // quietly converting the wxBitmap. Contributed by Frederic Villeneuve
172 // <frederic.villeneuve@natinst.com>
4fe5383d
VZ
173 wxBitmap GetBitmapForDC(wxDC& dc) const;
174
175protected:
176 // common part of all ctors
177 void Init();
7b46ecac 178
6d167489
VZ
179 virtual wxGDIImageRefData *CreateData() const
180 { return new wxBitmapRefData; }
181
4fe5383d 182private:
6d167489
VZ
183#ifdef __WIN32__
184 // common part of CopyFromIcon/CopyFromCursor for Win32
185 bool CopyFromIconOrCursor(const wxGDIImage& icon);
186#endif // __WIN32__
187
4fe5383d 188 DECLARE_DYNAMIC_CLASS(wxBitmap)
2bda0e17 189};
ce3ed50d 190
6d167489
VZ
191// ----------------------------------------------------------------------------
192// wxMask: a mono bitmap used for drawing bitmaps transparently.
193// ----------------------------------------------------------------------------
194
195class WXDLLEXPORT wxMask : public wxObject
196{
197public:
198 wxMask();
199
200 // Construct a mask from a bitmap and a colour indicating the transparent
201 // area
202 wxMask(const wxBitmap& bitmap, const wxColour& colour);
203
204 // Construct a mask from a bitmap and a palette index indicating the
205 // transparent area
206 wxMask(const wxBitmap& bitmap, int paletteIndex);
207
208 // Construct a mask from a mono bitmap (copies the bitmap).
209 wxMask(const wxBitmap& bitmap);
210
211 // construct a mask from the givne bitmap handle
212 wxMask(WXHBITMAP hbmp) { m_maskBitmap = hbmp; }
213
214 virtual ~wxMask();
215
216 bool Create(const wxBitmap& bitmap, const wxColour& colour);
217 bool Create(const wxBitmap& bitmap, int paletteIndex);
218 bool Create(const wxBitmap& bitmap);
219
220 // Implementation
221 WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; }
222 void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; }
223
224protected:
225 WXHBITMAP m_maskBitmap;
226
227 DECLARE_DYNAMIC_CLASS(wxMask)
228};
229
230// ----------------------------------------------------------------------------
231// wxBitmapHandler is a class which knows how to load/save bitmaps to/from file
232// ----------------------------------------------------------------------------
233
234class WXDLLEXPORT wxBitmapHandler : public wxGDIImageHandler
235{
236public:
237 wxBitmapHandler() { m_type = wxBITMAP_TYPE_INVALID; }
238 wxBitmapHandler(const wxString& name, const wxString& ext, long type)
239 : wxGDIImageHandler(name, ext, type)
240 {
241 }
242
243 // keep wxBitmapHandler derived from wxGDIImageHandler compatible with the
244 // old class which worked only with bitmaps
245 virtual bool Create(wxBitmap *bitmap,
246 void *data,
247 long flags,
248 int width, int height, int depth = 1);
249 virtual bool LoadFile(wxBitmap *bitmap,
250 const wxString& name,
251 long flags,
252 int desiredWidth, int desiredHeight);
253 virtual bool SaveFile(wxBitmap *bitmap,
254 const wxString& name,
255 int type,
256 const wxPalette *palette = NULL);
257
258 virtual bool Create(wxGDIImage *image,
259 void *data,
260 long flags,
261 int width, int height, int depth = 1);
262 virtual bool Load(wxGDIImage *image,
263 const wxString& name,
264 long flags,
265 int desiredWidth, int desiredHeight);
266 virtual bool Save(wxGDIImage *image,
267 const wxString& name,
268 int type);
269
270private:
271 DECLARE_DYNAMIC_CLASS(wxBitmapHandler)
272};
273
2bda0e17 274#endif
bbcdf8bc 275 // _WX_BITMAP_H_